From 9193b90f7e99d5807b72c20f92d91334d047cfd9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 7 Nov 2020 03:30:03 +0300 Subject: [PATCH] added autostop... Signed-off-by: Alex A. Naanou --- package.json | 2 +- runner.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 60d3f72..c9f9f43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "3.3.0", + "version": "3.3.1", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": { diff --git a/runner.js b/runner.js index 36ccb16..32a3270 100644 --- a/runner.js +++ b/runner.js @@ -29,6 +29,7 @@ module.Queue = object.Constructor('Queue', Array, { },{ pool_size: 8, poling_delay: 200, + autostop: false, __state: null, get state(){ @@ -134,7 +135,7 @@ module.Queue = object.Constructor('Queue', Array, { } else { this.trigger('taskCompleted', task, res) } } - // pole on empty queue... + // empty queue -> pole or stop... // // NOTE: we endup here in two cases: // - the pool is full @@ -144,11 +145,14 @@ module.Queue = object.Constructor('Queue', Array, { // // XXX will this be collected by the GC if it is polling??? if(this.length == 0 - && this.state == 'running' - && this.poling_delay){ - setTimeout( - this._run.bind(this), - this.poling_delay || 200) } + && this.state == 'running'){ + this.autostop ? + this.stop() + // pole... + : (this.poling_delay + && setTimeout( + this._run.bind(this), + this.poling_delay || 200)) } return this },