mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
now queue's first start will wait for items to be added... (experimental)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9f39d0a3dd
commit
b5eab1175d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "6.0.0",
|
||||
"version": "6.0.1",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
21
runner.js
21
runner.js
@ -101,6 +101,9 @@ object.Constructor('Queue', Array, {
|
||||
// Number of tasks to run before letting go of the exec frame...
|
||||
pause_after_sync: 4,
|
||||
|
||||
// XXX
|
||||
auto_start: false,
|
||||
|
||||
// Start synchronously...
|
||||
//
|
||||
// NOTE: this affects the start only, all other timeouts apply as-is...
|
||||
@ -177,11 +180,19 @@ object.Constructor('Queue', Array, {
|
||||
// NOTE: to start synchronously call .start(true), this will not
|
||||
// affect further operation...
|
||||
// XXX would be nice to run a specific number of tasks and stop...
|
||||
// XXX if starting empty need to start the timer only when something is
|
||||
// added...
|
||||
// XXX might be a good idea to let the user set .__wait_for_items...
|
||||
__wait_for_items: null,
|
||||
start: events.Event('start', function(handle, sync){
|
||||
// first start -- wait for items...
|
||||
if('__state' in this){
|
||||
this.__wait_for_items = true }
|
||||
// can't start while running...
|
||||
if(this.__state == 'running' || this.state == 'aborted'){
|
||||
if(this.__state == 'running' || this.__state == 'aborted'){
|
||||
return handle(false) }
|
||||
this.__state = 'running'
|
||||
// XXX if empty start polling...
|
||||
this.__run_tasks__(sync) }),
|
||||
stop: events.Event('stop', function(handle){
|
||||
// can't stop while not running...
|
||||
@ -263,6 +274,7 @@ object.Constructor('Queue', Array, {
|
||||
&& (pause == null
|
||||
|| c < pause)){
|
||||
var p = running.length
|
||||
delete this.__wait_for_items
|
||||
|
||||
this.runTask(this.__run_tasks__.bind(this))
|
||||
|
||||
@ -294,7 +306,9 @@ object.Constructor('Queue', Array, {
|
||||
// pause -- let other stuff run...
|
||||
: (this.pause_timeout || 0)
|
||||
|
||||
;(this.length == 0 && this.auto_stop) ?
|
||||
;(this.length == 0
|
||||
&& this.auto_stop
|
||||
&& !this.__wait_for_items) ?
|
||||
// auto-stop...
|
||||
this.__onempty__()
|
||||
// pole / pause...
|
||||
@ -523,11 +537,12 @@ object.Constructor('Queue', Array, {
|
||||
|
||||
// Like Queue(..) but adds terminal states and conversion to promises...
|
||||
//
|
||||
// XXX Object.freeze(..) this when done... ???
|
||||
// XXX find a better name...
|
||||
var FinalizableQueue =
|
||||
module.FinalizableQueue =
|
||||
object.Constructor('FinalizableQueue', Queue, {
|
||||
auto_stop: true,
|
||||
|
||||
__onempty__: function(){
|
||||
return this.trigger('done') },
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user