mirror of
				https://github.com/1disk/edp445.git
				synced 2024-08-14 22:47:02 +00:00 
			
		
		
		
	Changed alot of things.
This commit is contained in:
		
							parent
							
								
									a5a0523e5a
								
							
						
					
					
						commit
						3513d5390c
					
				
					 2016 changed files with 336930 additions and 9 deletions
				
			
		
							
								
								
									
										75
									
								
								node_modules/asynckit/lib/iterate.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								node_modules/asynckit/lib/iterate.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,75 @@ | |||
| var async = require('./async.js') | ||||
|   , abort = require('./abort.js') | ||||
|   ; | ||||
| 
 | ||||
| // API
 | ||||
| module.exports = iterate; | ||||
| 
 | ||||
| /** | ||||
|  * Iterates over each job object | ||||
|  * | ||||
|  * @param {array|object} list - array or object (named list) to iterate over | ||||
|  * @param {function} iterator - iterator to run | ||||
|  * @param {object} state - current job status | ||||
|  * @param {function} callback - invoked when all elements processed | ||||
|  */ | ||||
| function iterate(list, iterator, state, callback) | ||||
| { | ||||
|   // store current index
 | ||||
|   var key = state['keyedList'] ? state['keyedList'][state.index] : state.index; | ||||
| 
 | ||||
|   state.jobs[key] = runJob(iterator, key, list[key], function(error, output) | ||||
|   { | ||||
|     // don't repeat yourself
 | ||||
|     // skip secondary callbacks
 | ||||
|     if (!(key in state.jobs)) | ||||
|     { | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     // clean up jobs
 | ||||
|     delete state.jobs[key]; | ||||
| 
 | ||||
|     if (error) | ||||
|     { | ||||
|       // don't process rest of the results
 | ||||
|       // stop still active jobs
 | ||||
|       // and reset the list
 | ||||
|       abort(state); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       state.results[key] = output; | ||||
|     } | ||||
| 
 | ||||
|     // return salvaged results
 | ||||
|     callback(error, state.results); | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Runs iterator over provided job element | ||||
|  * | ||||
|  * @param   {function} iterator - iterator to invoke | ||||
|  * @param   {string|number} key - key/index of the element in the list of jobs | ||||
|  * @param   {mixed} item - job description | ||||
|  * @param   {function} callback - invoked after iterator is done with the job | ||||
|  * @returns {function|mixed} - job abort function or something else | ||||
|  */ | ||||
| function runJob(iterator, key, item, callback) | ||||
| { | ||||
|   var aborter; | ||||
| 
 | ||||
|   // allow shortcut if iterator expects only two arguments
 | ||||
|   if (iterator.length == 2) | ||||
|   { | ||||
|     aborter = iterator(item, async(callback)); | ||||
|   } | ||||
|   // otherwise go with full three arguments
 | ||||
|   else | ||||
|   { | ||||
|     aborter = iterator(item, key, async(callback)); | ||||
|   } | ||||
| 
 | ||||
|   return aborter; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue