From 71b9b444cbda26c4efd5c51dd4702209270faff6 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 2 Dec 2020 06:12:39 +0300 Subject: [PATCH] added queue handler actions + refactoring... Signed-off-by: Alex A. Naanou --- Viewer/features/core.js | 28 ++++++++++++++- Viewer/features/examples.js | 7 ++++ Viewer/features/metadata.js | 14 ++------ Viewer/features/sharp.js | 1 + Viewer/imagegrid/images.js | 72 ++++++++++++------------------------- Viewer/package-lock.json | 6 ++-- Viewer/package.json | 2 +- 7 files changed, 63 insertions(+), 67 deletions(-) diff --git a/Viewer/features/core.js b/Viewer/features/core.js index b7b7b7f9..c97fd35d 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2519,6 +2519,7 @@ function(func){ // automate this... // ...would also be nice to automate this via a chunk iterator so // as not to block... +// XXX handle errors... (???) var queuedAction = module.queuedAction = function(name, func){ @@ -2529,7 +2530,6 @@ function(name, func){ return object.mixin( Queued(function(...args){ var that = this - // XXX handle errors... (???) return new Promise(function(resolve, reject){ that.queue(name, opts || {}) .push(function(){ @@ -2543,6 +2543,32 @@ function(name, func){ }) } +var queueHandler = +module.queueHandler = +function(name, func){ + var args = [...arguments] + func = args.pop() + var [name, opts] = args + + return object.mixin( + Queued(function(items, ...args){ + var that = this + return new Promise(function(resolve, reject){ + var q = that.queue(name, + Object.assign( + {}, + opts || {}, + { handler: function(item){ + return func.call(that, item, ...args) } })) + q.push(...(items instanceof Array ? items : [items])) + q.then(resolve, reject) }) }), + { + toString: function(){ + return `core.queueHandler('${name}',\n\t${ + object.normalizeIndent( '\t'+ func.toString() ) })` }, + }) } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Viewer/features/examples.js b/Viewer/features/examples.js index 0915564e..d3a750b6 100755 --- a/Viewer/features/examples.js +++ b/Viewer/features/examples.js @@ -279,6 +279,13 @@ var ExampleActions = actions.Actions({ for(var i=0; i