From 8a02178a243acfac839bf2b61de2b906dafcedb7 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 5 Dec 2020 03:26:42 +0300 Subject: [PATCH] fixed last of the task/queue issues, now should be fully usable... Signed-off-by: Alex A. Naanou --- Viewer/features/core.js | 8 ++-- Viewer/features/examples.js | 74 +++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Viewer/features/core.js b/Viewer/features/core.js index aa8bfe92..70f0ba34 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2531,8 +2531,6 @@ function(func){ // during the later form 'sync' is passed to .Task(..) in the correct // position... // (see ig-types' runner.TaskManager(..) for more info) -// -// XXX use action.name to identify the task instead of the title... var taskAction = module.taskAction = function(title, func){ @@ -2548,8 +2546,10 @@ function(title, func){ action = Task(function(...args){ if(args[0] == 'sync' || args[0] == 'async'){ pre_args = [args.shift(), title] } - // XXX should we set the task name to action.name?? - return this.tasks.Task(...pre_args, func.bind(this), ...args) }), + return Object.assign( + this.tasks.Task(...pre_args, func.bind(this), ...args), + // make this searchable by .tasks.named(..)... + { name: action.name }) }), { title, toString: function(){ diff --git a/Viewer/features/examples.js b/Viewer/features/examples.js index 598b598f..354c1f26 100755 --- a/Viewer/features/examples.js +++ b/Viewer/features/examples.js @@ -269,8 +269,45 @@ var ExampleActions = actions.Actions({ // Tasks... + // + // NOTE: action name and task name should be the same to avoid + // confusion... + // XXX it would be quite complicated to support both and + // confusing to support either... + exampleTask: ['- Test/', + core.taskAction('Example task', + function(ticket, ...args){ + console.log('###', ticket.title+':', 'START:', ...args, + '\n\t\t(supported messages: "stop", "break", "error", ...)') + ticket.onmessage(function(msg){ + // stop... + if(msg == 'stop'){ + console.log('###', ticket.title+':', 'STOP', ...args) + ticket.resolve(...args) + // break... + } else if(msg == 'break'){ + console.log('###', ticket.title+':', 'BREAK', ...args) + ticket.reject(...args) + // error... + } else if(msg == 'error'){ + console.log('###', ticket.title+':', 'ERROR', ...args) + throw new Error('Task error') + // other... + } else { + console.log('###', ticket.title+':', 'Got message:', msg, ...args) } }) })], + exampleSessionTask: ['- Test/', + core.sessionTaskAction('Example session task', + function(ticket, ...args){ + console.log('###', ticket.title+':', 'START:', ...args) + ticket.onmessage('stop', function(){ + console.log('###', ticket.title+':', 'STOP:', ...args) + ticket.resolve(...args) }) })], + + // Queued tasks... + // + // queued actions... exampleQueuedAction: ['- Test/', - core.queuedAction('exampleQueuedAction', {quiet: true}, function(timeout=500, ...args){ + core.queuedAction('Example queued action', {quiet: true}, function(timeout=500, ...args){ console.log('Queued action!!', ...args) return new Promise(function(resolve){ setTimeout(resolve, timeout) }) })], @@ -278,7 +315,7 @@ var ExampleActions = actions.Actions({ function(count=100, timeout=100){ for(var i=0; i