Created
October 24, 2011 16:04
-
-
Save soney/1309386 to your computer and use it in GitHub Desktop.
A function that, given an array and a mapping function that uses a callback, calls a callback with the mapped array as a parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var callback_map = function(arr, func, callback) { | |
var rv = []; | |
var waiting_for = arr.length; | |
arr.forEach(function(item, index) { | |
func(item, function(mapped) { | |
rv[index] = mapped; | |
waiting_for--; | |
if(waiting_for <= 0) { | |
callback(rv); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment