mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
fixed last of the task/queue issues, now should be fully usable...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
00a72832b0
commit
8a02178a24
@ -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(){
|
||||
|
||||
@ -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<count; i++){
|
||||
this.exampleQueuedAction(timeout) } }],
|
||||
|
||||
// handler actions...
|
||||
exampleQueueHandlerAction: ['- Test/',
|
||||
core.queueHandler('Example queue handler action',
|
||||
{quiet: true},
|
||||
@ -304,39 +341,6 @@ var ExampleActions = actions.Actions({
|
||||
return new Promise(function(resolve){
|
||||
setTimeout(resolve, timeout || 100) }) })],
|
||||
|
||||
//
|
||||
// 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('exampleTask',
|
||||
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('exampleSessionTask',
|
||||
function(ticket, ...args){
|
||||
console.log('###', ticket.title+':', 'START:', ...args)
|
||||
ticket.onmessage('stop', function(){
|
||||
console.log('###', ticket.title+':', 'STOP:', ...args)
|
||||
ticket.resolve(...args) }) })],
|
||||
})
|
||||
|
||||
var Example =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user