Skip to content

Commit

Permalink
refactor: Add options to base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsgames committed Mar 15, 2023
1 parent 50674f5 commit 63b8a85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { BatchCommonOptions, BatchPredicateOptions, BatchTaskOptions } from
import { interrupt, SharedBase } from './shared-base';
import type { Input, Job, RunnableTask, Task } from './types';

export class Batch extends SharedBase {
export class Batch extends SharedBase<BatchCommonOptions> {

static #processGlobalTaskInput<A, B>(
taskOptions: BatchTaskOptions<A, B>
Expand Down Expand Up @@ -445,7 +445,7 @@ export class Batch extends SharedBase {
return await this.#runJob(() => Promise.resolve(task(...args)));
}

set options(options: BatchCommonOptions) {
override set options(options: BatchCommonOptions) {
if (typeof options.batchSize !== 'number' || !Number.isInteger(options.batchSize))
throw new Error('Parameter `batchSize` invalid!');

Expand Down
4 changes: 2 additions & 2 deletions src/concurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ConcurrencyCommonOptions, ConcurrencyPredicateOptions, Concurrency
import { interrupt, SharedBase } from './shared-base';
import type { Input, Job, RunnableTask, Task } from './types';

export class Concurrency extends SharedBase {
export class Concurrency extends SharedBase<ConcurrencyCommonOptions> {

static #processGlobalTaskInput<A, B>(
taskOptions: ConcurrencyTaskOptions<A, B>
Expand Down Expand Up @@ -437,7 +437,7 @@ export class Concurrency extends SharedBase {
return await this.#runJob(() => Promise.resolve(task(...args)));
}

set options(options: ConcurrencyCommonOptions) {
override set options(options: ConcurrencyCommonOptions) {
if (typeof options.maxConcurrency !== 'number' || !Number.isInteger(options.maxConcurrency))
throw new Error('Parameter `maxConcurrency` invalid!');

Expand Down
7 changes: 6 additions & 1 deletion src/shared-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Input, RunnableTask, Task } from './types';

export const interrupt = {};

export abstract class SharedBase {
export abstract class SharedBase<Options> {

/**
* Performs the specified `task` for each element in the input.
Expand Down Expand Up @@ -38,6 +38,11 @@ export abstract class SharedBase {
*/
abstract run<A, B>(task: RunnableTask<A, B>, ...args: A[]): Promise<B>;

/**
* Instance Options.
*/
abstract set options(options: Options);

/**
* Calls a defined `task` function on each element of the `input`, and returns an array that contains the results.
*
Expand Down

0 comments on commit 63b8a85

Please sign in to comment.