From d7d6857dae4f5a32c2776cb10dc312a123d669b9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 12 Nov 2020 05:18:28 +0300 Subject: [PATCH] tweaking... Signed-off-by: Alex A. Naanou --- Viewer/features/core.js | 101 +++++++++++++++++++++++++++++++++++++++ Viewer/features/sharp.js | 6 +++ 2 files changed, 107 insertions(+) diff --git a/Viewer/features/core.js b/Viewer/features/core.js index 487fcf23..674375bd 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2439,6 +2439,107 @@ function(title, func){ }) } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var Task = +module.Task = +object.Constructor('Task', { +}) + + +// +// eventMethod(name[, func]) +// eventMethod(name[, func], 'hidden') +// -> method +// +// eventMethod(name[, func], 'visible') +// -> method +// +// +// Bind handler... +// method(handler) +// -> this +// +// Unbind handler... +// method(handler, false) +// -> this +// +// Trigger handlers... +// method(...args) +// -> this +// +// +// func(handle, ...args) +// +// +// XXX move this someplace generic... +var eventMethod = function(name, func, mode='hidden'){ + // no func given... + if(typeof(func) != 'function'){ + mode = func + func = undefined } + // hidden handler list... + var handlers = mode == 'hidden' && [] + + return function(func, mode){ + handlers = handlers === false ? + this['__'+name] + : handlers + // bind/unbind event handler... + if(typeof(func) == 'function'){ + mode === false ? + handlers.splice(handlers.indexOf(func), 1) + : handlers.push(func) + // trigger the event... + } else { + var args = [...arguments] + var handle = function(){ + handlers + .forEach(function(handler){ + handler(...args) }) } + func ? + func.call(this, handle, ...args) + : handle(...args)} + return this } } + +var taskAction = +module.taskAction = +function(title, func){ + return Object.assign( + task(function(){ + var that = this + + // XXX + var ticket = { + // XXX revise naming... + start: eventMethod('start', function(handle, ...args){ + }), + pause: eventMethod('pause', function(handle, ...args){ + }), + abort: eventMethod('abort', function(handle, ...args){ + if(!this.state != 'done'){ + this.abortTask(title) + handle(...args) } }), + + // can be: + // - ready + // - running + // - done + get state(){ + }, + } + + return func.call(this, ticket, ...args) + .then(function(){ + }) + .catch(function(){ + }) }), + { + toString: function(){ + return `core.taskAction('${ title }', \n${ func.toString() })` }, + }) } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var makeTaskAction = diff --git a/Viewer/features/sharp.js b/Viewer/features/sharp.js index e56857c8..70e0d579 100755 --- a/Viewer/features/sharp.js +++ b/Viewer/features/sharp.js @@ -601,11 +601,17 @@ var SharpActions = actions.Actions({ var CHUNK_SIZE = 4 + // XXX this seems to be called prematurely... abort.cleanup(function(reason, res){ + console.log('!!!!!!', + logger && logger.log.length, + reason, res) + /* logger && logger.emit('done') && reason == 'aborted' && logger.emit(res) + //*/ delete that.__cache_metadata_reading }) // handle logging and processing list...