diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/testnet-faucets/src/ts/dispatch_queue.ts | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/testnet-faucets/src/ts/dispatch_queue.ts')
-rw-r--r-- | packages/testnet-faucets/src/ts/dispatch_queue.ts | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/packages/testnet-faucets/src/ts/dispatch_queue.ts b/packages/testnet-faucets/src/ts/dispatch_queue.ts deleted file mode 100644 index 3d0958fbf..000000000 --- a/packages/testnet-faucets/src/ts/dispatch_queue.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { intervalUtils, logUtils } from '@0x/utils'; -import * as _ from 'lodash'; - -import { errorReporter } from './error_reporter'; - -const MAX_QUEUE_SIZE = 500; -const DEFAULT_QUEUE_INTERVAL_MS = 1000; - -export class DispatchQueue { - private readonly _queueIntervalMs: number; - private readonly _queue: Array<() => Promise<void>>; - private _queueIntervalIdIfExists?: NodeJS.Timer; - constructor() { - this._queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS; - this._queue = []; - this._start(); - } - public add(taskAsync: () => Promise<void>): boolean { - if (this.isFull()) { - return false; - } - this._queue.push(taskAsync); - return true; - } - public size(): number { - return this._queue.length; - } - public isFull(): boolean { - return this.size() >= MAX_QUEUE_SIZE; - } - public stop(): void { - if (!_.isUndefined(this._queueIntervalIdIfExists)) { - intervalUtils.clearAsyncExcludingInterval(this._queueIntervalIdIfExists); - } - } - private _start(): void { - this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( - async () => { - const taskAsync = this._queue.shift(); - if (_.isUndefined(taskAsync)) { - return Promise.resolve(); - } - await taskAsync(); - }, - this._queueIntervalMs, - (err: Error) => { - logUtils.log(`Unexpected err: ${err} - ${JSON.stringify(err)}`); - // tslint:disable-next-line:no-floating-promises - errorReporter.reportAsync(err); - }, - ); - } -} |