aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets/src/ts/request_queue.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/testnet-faucets/src/ts/request_queue.ts')
-rw-r--r--packages/testnet-faucets/src/ts/request_queue.ts80
1 files changed, 40 insertions, 40 deletions
diff --git a/packages/testnet-faucets/src/ts/request_queue.ts b/packages/testnet-faucets/src/ts/request_queue.ts
index 37b5505f8..20f2833a1 100644
--- a/packages/testnet-faucets/src/ts/request_queue.ts
+++ b/packages/testnet-faucets/src/ts/request_queue.ts
@@ -11,46 +11,46 @@ const MAX_QUEUE_SIZE = 500;
const DEFAULT_QUEUE_INTERVAL_MS = 1000;
export class RequestQueue {
- protected queueIntervalMs: number;
- protected queue: string[];
- protected queueIntervalId: NodeJS.Timer;
- protected web3: Web3;
- constructor(web3: any) {
- this.queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS;
- this.queue = [];
+ protected queueIntervalMs: number;
+ protected queue: string[];
+ protected queueIntervalId: NodeJS.Timer;
+ protected web3: Web3;
+ constructor(web3: any) {
+ this.queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS;
+ this.queue = [];
- this.web3 = web3;
+ this.web3 = web3;
- this.start();
- }
- public add(recipientAddress: string): boolean {
- if (this.isFull()) {
- return false;
- }
- this.queue.push(recipientAddress);
- return true;
- }
- public size(): number {
- return this.queue.length;
- }
- public isFull(): boolean {
- return this.size() >= MAX_QUEUE_SIZE;
- }
- protected start() {
- this.queueIntervalId = timers.setInterval(() => {
- const recipientAddress = this.queue.shift();
- if (_.isUndefined(recipientAddress)) {
- return;
- }
- // tslint:disable-next-line:no-floating-promises
- this.processNextRequestFireAndForgetAsync(recipientAddress);
- }, this.queueIntervalMs);
- }
- protected stop() {
- clearInterval(this.queueIntervalId);
- }
- // tslint:disable-next-line:prefer-function-over-method
- protected async processNextRequestFireAndForgetAsync(recipientAddress: string) {
- throw new Error('Expected processNextRequestFireAndForgetAsync to be implemented by a subclass');
- }
+ this.start();
+ }
+ public add(recipientAddress: string): boolean {
+ if (this.isFull()) {
+ return false;
+ }
+ this.queue.push(recipientAddress);
+ return true;
+ }
+ public size(): number {
+ return this.queue.length;
+ }
+ public isFull(): boolean {
+ return this.size() >= MAX_QUEUE_SIZE;
+ }
+ protected start() {
+ this.queueIntervalId = timers.setInterval(() => {
+ const recipientAddress = this.queue.shift();
+ if (_.isUndefined(recipientAddress)) {
+ return;
+ }
+ // tslint:disable-next-line:no-floating-promises
+ this.processNextRequestFireAndForgetAsync(recipientAddress);
+ }, this.queueIntervalMs);
+ }
+ protected stop() {
+ clearInterval(this.queueIntervalId);
+ }
+ // tslint:disable-next-line:prefer-function-over-method
+ protected async processNextRequestFireAndForgetAsync(recipientAddress: string) {
+ throw new Error('Expected processNextRequestFireAndForgetAsync to be implemented by a subclass');
+ }
}