Created
February 11, 2014 15:52
-
-
Save dogles/8937583 to your computer and use it in GitHub Desktop.
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
com.dongxiguo.continuation.utils.ForkJoin.fork = function(threadIdentifiers,handler) { | |
if(Lambda.empty(threadIdentifiers)) throw "threadIdentifiers must not be empty!"; | |
var counter = 1; | |
var quickJoinHandler = null; | |
var $it0 = $iterator(threadIdentifiers)(); | |
while( $it0.hasNext() ) { | |
var id = $it0.next(); | |
counter++; | |
var isJoined = [false]; | |
handler(id,(function(isJoined) { | |
return function(joinHandler) { | |
if(isJoined[0]) throw "Cannot join twice in one thread!"; else { | |
isJoined[0] = true; | |
if(--counter == 0) joinHandler(); else quickJoinHandler = joinHandler; | |
} | |
}; | |
})(isJoined)); | |
} | |
if(--counter == 0) quickJoinHandler(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment