mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +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
 | // 		during the later form 'sync' is passed to .Task(..) in the correct
 | ||||||
| // 		position...
 | // 		position...
 | ||||||
| // 		(see ig-types' runner.TaskManager(..) for more info)
 | // 		(see ig-types' runner.TaskManager(..) for more info)
 | ||||||
| //
 |  | ||||||
| // XXX use action.name to identify the task instead of the title...
 |  | ||||||
| var taskAction = | var taskAction = | ||||||
| module.taskAction = | module.taskAction = | ||||||
| function(title, func){ | function(title, func){ | ||||||
| @ -2548,8 +2546,10 @@ function(title, func){ | |||||||
| 		action = Task(function(...args){ | 		action = Task(function(...args){ | ||||||
| 			if(args[0] == 'sync' || args[0] == 'async'){ | 			if(args[0] == 'sync' || args[0] == 'async'){ | ||||||
| 				pre_args = [args.shift(), title] } | 				pre_args = [args.shift(), title] } | ||||||
| 			// XXX should we set the task name to action.name??
 | 			return Object.assign( | ||||||
| 			return this.tasks.Task(...pre_args, func.bind(this), ...args) }), | 				this.tasks.Task(...pre_args, func.bind(this), ...args),  | ||||||
|  | 				// make this searchable by .tasks.named(..)...
 | ||||||
|  | 				{ name: action.name }) }), | ||||||
| 		{ | 		{ | ||||||
| 			title, | 			title, | ||||||
| 			toString: function(){ | 			toString: function(){ | ||||||
|  | |||||||
| @ -269,8 +269,45 @@ var ExampleActions = actions.Actions({ | |||||||
| 
 | 
 | ||||||
| 	// Tasks...
 | 	// 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/', | 	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) | 			console.log('Queued action!!', ...args) | ||||||
| 			return new Promise(function(resolve){ | 			return new Promise(function(resolve){ | ||||||
| 				setTimeout(resolve, timeout) }) })], | 				setTimeout(resolve, timeout) }) })], | ||||||
| @ -278,7 +315,7 @@ var ExampleActions = actions.Actions({ | |||||||
| 		function(count=100, timeout=100){ | 		function(count=100, timeout=100){ | ||||||
| 			for(var i=0; i<count; i++){ | 			for(var i=0; i<count; i++){ | ||||||
| 				this.exampleQueuedAction(timeout) } }], | 				this.exampleQueuedAction(timeout) } }], | ||||||
| 
 | 	// handler actions...
 | ||||||
| 	exampleQueueHandlerAction: ['- Test/', | 	exampleQueueHandlerAction: ['- Test/', | ||||||
| 		core.queueHandler('Example queue handler action',  | 		core.queueHandler('Example queue handler action',  | ||||||
| 			{quiet: true},  | 			{quiet: true},  | ||||||
| @ -304,39 +341,6 @@ var ExampleActions = actions.Actions({ | |||||||
| 				return new Promise(function(resolve){ | 				return new Promise(function(resolve){ | ||||||
| 					setTimeout(resolve, timeout || 100) }) })], | 					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 =  | var Example =  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user