v1.0.3: use index as well
This commit is contained in:
		
							parent
							
								
									9beae76631
								
							
						
					
					
						commit
						178672ad0d
					
				| @ -37,7 +37,7 @@ | |||||||
| 
 | 
 | ||||||
|                 var p; |                 var p; | ||||||
|                 try { |                 try { | ||||||
|                     p = doStuff(task); |                     p = doStuff(task, index, arr); | ||||||
|                 } catch (e) { |                 } catch (e) { | ||||||
|                     // we need to handle, and bubble, synchronous errors
 |                     // we need to handle, and bubble, synchronous errors
 | ||||||
|                     error = e; |                     error = e; | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | { | ||||||
|  |   "name": "batchasync", | ||||||
|  |   "version": "1.0.3", | ||||||
|  |   "lockfileVersion": 1 | ||||||
|  | } | ||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "batchasync", |   "name": "batchasync", | ||||||
|   "version": "1.0.2", |   "version": "1.0.3", | ||||||
|   "description": "Like forEachAsync, or Promise.all(), but handling a bounded number of items at any given time.", |   "description": "Like forEachAsync, or Promise.all(), but handling a bounded number of items at any given time.", | ||||||
|   "main": "batchasync.js", |   "main": "batchasync.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								test.js
									
									
									
									
									
								
							| @ -6,11 +6,12 @@ | |||||||
| 
 | 
 | ||||||
|     function testBatch() { |     function testBatch() { | ||||||
|         var timeouts = [100, 80, 20, 500, 50, 30, 200, 300]; |         var timeouts = [100, 80, 20, 500, 50, 30, 200, 300]; | ||||||
|  |         console.info(timeouts); | ||||||
|         var tasks = timeouts.map(function(timeout, i) { |         var tasks = timeouts.map(function(timeout, i) { | ||||||
|             return function() { |             return function() { | ||||||
|                 return promiseTimeout(timeout).then(function() { |                 return promiseTimeout(timeout).then(function() { | ||||||
|                     console.log("task:", i, timeouts[i]); |                     //console.log("task:", i, timeouts[i]);
 | ||||||
|                     return i; |                     return i + ":" + timeouts[i]; | ||||||
|                 }); |                 }); | ||||||
|             }; |             }; | ||||||
|         }); |         }); | ||||||
| @ -71,7 +72,7 @@ | |||||||
|                     } |                     } | ||||||
|                     return null; |                     return null; | ||||||
|                 }) |                 }) | ||||||
|                     .then(function(results) { |                     .then(function(/*results*/) { | ||||||
|                         var e = new Error("should not pass sync exception!"); |                         var e = new Error("should not pass sync exception!"); | ||||||
|                         e.FAIL = true; |                         e.FAIL = true; | ||||||
|                         throw e; |                         throw e; | ||||||
| @ -90,7 +91,7 @@ | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function promiseTimeout(timeout) { |     function promiseTimeout(timeout) { | ||||||
|         return new Promise(function(resolve, reject) { |         return new Promise(function(resolve) { | ||||||
|             setTimeout(resolve, timeout); |             setTimeout(resolve, timeout); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| @ -99,7 +100,7 @@ | |||||||
|         .then(function() { |         .then(function() { | ||||||
|             console.info("PROBABLY PASSED"); |             console.info("PROBABLY PASSED"); | ||||||
|             console.info( |             console.info( | ||||||
|                 "We tested what could be tested without knowing Passed what could be tested Do the results make sense?" |                 "We tested what could be tested. Do the results make sense?" | ||||||
|             ); |             ); | ||||||
|         }) |         }) | ||||||
|         .catch(function(e) { |         .catch(function(e) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user