Created
November 19, 2013 21:48
-
-
Save jimrubenstein/7553160 to your computer and use it in GitHub Desktop.
This file contains 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
__d("adsAsyncUtils", [], function(a, b, c, d, e, f) { | |
var g = 30; | |
function h(arr, iter, progress) { | |
"use strict"; | |
this.$ParallelForEach0 = arr; //array | |
this.$ParallelForEach1 = 1; //concurrency | |
this.$ParallelForEach2 = iter; //iterator | |
this.$ParallelForEach3 = progress; //progress complete | |
this.$ParallelForEach4 = 0; //working "threads" | |
this.$ParallelForEach5 = 0; | |
this.$ParallelForEach6 = 0; | |
this.$ParallelForEach7 = 60000; //timeoutLimit | |
this.$ParallelForEach8 = null; //TimeoutHandler | |
//this.$ParallelForEach9 == context | |
//this.$ParallelForeacha == exceptionHandler | |
} | |
h.prototype.setTimeoutLimit = function(j) { | |
"use strict"; | |
this.$ParallelForEach7 = j; | |
return this; | |
}; | |
h.prototype.setTimeoutHandler = function(j) { | |
"use strict"; | |
this.$ParallelForEach8 = j; | |
return this; | |
}; | |
h.prototype.setContext = function(j) { | |
"use strict"; | |
this.$ParallelForEach9 = j; | |
return this; | |
}; | |
h.prototype.setExceptionHandler = function(j) { | |
"use strict"; | |
this.$ParallelForEacha = j; | |
return this; | |
}; | |
h.prototype.setConcurrency = function(j) { | |
"use strict"; | |
this.$ParallelForEach1 = j; | |
return this; | |
}; | |
h.prototype.run = function() { | |
"use strict"; | |
var j = this; | |
if (j.$ParallelForEach4 < j.$ParallelForEach1) | |
j.hasNext(function(k) { | |
if (k) { | |
j.$ParallelForEachb(0); | |
j.run(); | |
} else if (j.$ParallelForEach4 === 0) | |
j.$ParallelForEach3.call(j.$ParallelForEach9 || null); | |
}); | |
}; | |
h.prototype.hasNext = function(j) { | |
"use strict"; | |
j(this.$ParallelForEach4 < this.$ParallelForEach0.length); | |
}; | |
h.prototype.numRunning = function() { | |
"use strict"; | |
return this.$ParallelForEach4 - this.$ParallelForEach5; | |
}; | |
h.prototype.next = function() { | |
"use strict"; | |
return this.$ParallelForEach0[this.$ParallelForEach4++]; | |
}; | |
h.prototype.$ParallelForEachb = function(j) { | |
"use strict"; | |
var k = this.$ParallelForEach4, l = this.next(); | |
if (j && j % g === 0) { | |
setTimeout(this.$ParallelForEachc.bind(this, l, k, 0), 1); | |
} else | |
this.$ParallelForEachc(l, k, j); | |
}; | |
h.prototype.$ParallelForEachc = function(j, k, l) { | |
"use strict"; | |
var m = null; | |
if (this.$ParallelForEach8) | |
setTimeout(this.$ParallelForEach8, this.$ParallelForEach7); | |
try { | |
this.$ParallelForEach2.call(this.$ParallelForEach9 || null, j, k, this.$ParallelForEachd.bind(this, l, m)); | |
} catch (n) { | |
if (this.$ParallelForEacha) { | |
this.$ParallelForEacha(n); | |
this.$ParallelForEachd(l, m); | |
} else | |
throw n; | |
} | |
}; | |
h.prototype.$ParallelForEachd = function(j, k) { | |
"use strict"; | |
if (k) | |
clearTimeout(k); | |
var l = this; | |
++l.$ParallelForEach5; | |
++l.$ParallelForEach6; | |
l.hasNext(function(m) { | |
--l.$ParallelForEach6; | |
if (m) { | |
l.$ParallelForEachb(j + 1); | |
} else if (l.$ParallelForEach6 === 0 && l.numRunning() === 0) | |
l.$ParallelForEach3.call(l.$ParallelForEach9 || null); | |
}); | |
}; | |
var foreach = function(arr, k, l, context) { | |
var n = new h(arr, k, l); | |
n.setConcurrency(1).setContext(context).run(); | |
}; | |
e.exports = {forEach: foreach}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment