mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 11:20:09 +00:00 
			
		
		
		
	removed makeDeferredsQ(..) as it's no longer used and is fully replaces by makeDeferredPool(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									a451547470
								
							
						
					
					
						commit
						79793caf48
					
				
							
								
								
									
										138
									
								
								ui/lib/jli.js
									
									
									
									
									
								
							
							
						
						
									
										138
									
								
								ui/lib/jli.js
									
									
									
									
									
								
							| @ -590,144 +590,6 @@ jQuery.fn.sortChildren = function(func){ | |||||||
| 
 | 
 | ||||||
| /************************************************** Deferred utils ***/ | /************************************************** Deferred utils ***/ | ||||||
| 
 | 
 | ||||||
| // Deferred worker queue
 |  | ||||||
| //
 |  | ||||||
| // This will either create a new queue or attach to the tail of an 
 |  | ||||||
| // existing queue (deferred) if given.
 |  | ||||||
| //
 |  | ||||||
| // This will return a deferred object with several extensions:
 |  | ||||||
| //
 |  | ||||||
| // 		.enqueue(worker, ...)
 |  | ||||||
| // 			Add a worker to the queue.
 |  | ||||||
| // 			A worker is triggered by the previous worker in queue 
 |  | ||||||
| // 			getting resolved. 
 |  | ||||||
| // 			NOTE: A worker must return a deferred.
 |  | ||||||
| // 			NOTE: all the arguments to this except for the first (the 
 |  | ||||||
| // 				worker itself) will be passed to the worker when it is 
 |  | ||||||
| // 				called.
 |  | ||||||
| //
 |  | ||||||
| // 		.start()
 |  | ||||||
| // 			Start the first worker.
 |  | ||||||
| //
 |  | ||||||
| // 		.kill()
 |  | ||||||
| // 			Stop the queue, preventing any new workers from starting.
 |  | ||||||
| // 			NOTE: this will not kill the currently running worker.
 |  | ||||||
| // 			NOTE: after a queue is killed it can not be restarted.
 |  | ||||||
| //
 |  | ||||||
| // 		.isWorking()
 |  | ||||||
| // 			will return true if there is at least one worker still not
 |  | ||||||
| // 			resolved, false otherwise.
 |  | ||||||
| // 			NOTE: if the queue is killed, this will always return false.
 |  | ||||||
| //
 |  | ||||||
| //
 |  | ||||||
| // NOTE: the queue is not started by default.
 |  | ||||||
| // NOTE: one queue is guaranteed to work in a sequence, to run several 
 |  | ||||||
| // 		pipelines in parallel use two or more queues.
 |  | ||||||
| // NOTE: running queues in parallel depends on the actual context in
 |  | ||||||
| // 		use (browser/node.js/...).
 |  | ||||||
| //
 |  | ||||||
| // XXX should this be restartable???
 |  | ||||||
| // XXX check if this leaks used nodes...
 |  | ||||||
| function makeDeferredsQ(first){ |  | ||||||
| 	first = first == null ? $.Deferred() : first |  | ||||||
| 
 |  | ||||||
| 	var last = first |  | ||||||
| 
 |  | ||||||
| 	// XXX make this a deferred-like cleanly, rather than by monkey patching...
 |  | ||||||
| 	var queue = $.Deferred() |  | ||||||
| 
 |  | ||||||
| 	// Add a worker to queue...
 |  | ||||||
| 	//
 |  | ||||||
| 	// NOTE: .enqueue(...) accepts a worker and any number of the arguments
 |  | ||||||
| 	// 		to be passed to the worker when it's its turn.
 |  | ||||||
| 	// NOTE: the worker must porduce a deferred/promice.
 |  | ||||||
| 	queue.enqueue = function(worker){ |  | ||||||
| 		var cur = $.Deferred() |  | ||||||
| 		var args = Array.apply(null, arguments).slice(1) |  | ||||||
| 
 |  | ||||||
| 		function run(){ |  | ||||||
| 			return worker.apply(null, args) |  | ||||||
| 				.done(function(o){  |  | ||||||
| 					cur.resolve(o)  |  | ||||||
| 				}) |  | ||||||
| 				.fail(function(){  |  | ||||||
| 					cur.resolve('fail')  |  | ||||||
| 				}) |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		last.done(function(){ |  | ||||||
| 
 |  | ||||||
| 			// XXX one way to stop and resume the queue execution is:
 |  | ||||||
| 			// 		1) add a "suspended" state
 |  | ||||||
| 			// 		2) in the "suspended" state bind the worker start to 
 |  | ||||||
| 			// 			.resume(...)
 |  | ||||||
| 			if(queue.state() == 'suspended'){ |  | ||||||
| 				queue.resumed(function(){ |  | ||||||
| 					run() |  | ||||||
| 				}) |  | ||||||
| 
 |  | ||||||
| 			// if we are killed drop the work...
 |  | ||||||
| 			} else if(queue.state() == 'resolved'){ |  | ||||||
| 				// this will kill the queue as we continue only on success...
 |  | ||||||
| 				cur.reject()  |  | ||||||
| 				return |  | ||||||
| 
 |  | ||||||
| 			// do the work now...
 |  | ||||||
| 			} else { |  | ||||||
| 				run() |  | ||||||
| 			} |  | ||||||
| 		}) |  | ||||||
| 
 |  | ||||||
| 		last = cur |  | ||||||
| 
 |  | ||||||
| 		return cur |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// Start the work...
 |  | ||||||
| 	queue.start = function(){ |  | ||||||
| 		first.resolve() |  | ||||||
| 		return this |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// Kill the queue...
 |  | ||||||
| 	queue.kill = function(){ |  | ||||||
| 		this.resolve() |  | ||||||
| 		return this |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/* XXX suspend interface... |  | ||||||
| 	// XXX change the state...
 |  | ||||||
| 	queue.suspend = function(){ |  | ||||||
| 		// XXX 
 |  | ||||||
| 		return this |  | ||||||
| 	} |  | ||||||
| 	// XXX change the state...
 |  | ||||||
| 	queue.resume = function(){ |  | ||||||
| 		// XXX 
 |  | ||||||
| 		return this |  | ||||||
| 	} |  | ||||||
| 	// XXX change the state...
 |  | ||||||
| 	queue.resumed = function(){ |  | ||||||
| 		// XXX 
 |  | ||||||
| 		return this |  | ||||||
| 	} |  | ||||||
| 	*/ |  | ||||||
| 
 |  | ||||||
| 	// Report work state...
 |  | ||||||
| 	// XXX make this a proper state, or integrate into the deferred in 
 |  | ||||||
| 	// 		a more natural way...
 |  | ||||||
| 	// 		...need a way to bind to this state change...
 |  | ||||||
| 	queue.isWorking = function(){ |  | ||||||
| 		if(queue.state() != 'resolved' && last.state() != 'resolved'){ |  | ||||||
| 			return true |  | ||||||
| 		} |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return queue |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| // Deferred worker pool...
 | // Deferred worker pool...
 | ||||||
| //
 | //
 | ||||||
| // 		makeDeferredPool([size][, paused]) -> pool
 | // 		makeDeferredPool([size][, paused]) -> pool
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user