update non-blocking forEach
This commit is contained in:
parent
77f4d8f3b9
commit
aea2473399
1 changed files with 34 additions and 13 deletions
|
@ -28,7 +28,7 @@
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.nonblockingForEach <f> Non-blocking forEach
|
||||
Ox.nonblockingForEach <f> Non-blocking forEach with synchronous iterator
|
||||
(col, iterator[, that], callback[, ms]) -> <u> undefined
|
||||
@*/
|
||||
Ox.nonblockingForEach = function(col, iterator, that, callback, ms) {
|
||||
|
@ -44,7 +44,7 @@
|
|||
time = +new Date();
|
||||
iterate();
|
||||
function iterate() {
|
||||
keys[i] in col && iterator.call(that, col[keys[i]], keys[i], col, function() {
|
||||
keys[i] in col && iterator.call(that, col[keys[i]], keys[i], col);
|
||||
if (++i < n) {
|
||||
if (+new Date() < time + ms) {
|
||||
iterate();
|
||||
|
@ -57,10 +57,31 @@
|
|||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.nonblockingMap <f> Non-blocking map with synchronous iterator
|
||||
(col, iterator[, that], callback) -> <u> undefined
|
||||
col <a|o|s> Collection
|
||||
iterator <f> Iterator function
|
||||
that <o> The iterator's this binding
|
||||
callback <f> Callback function
|
||||
<script>
|
||||
var time = +new Date();
|
||||
Ox.serialMap(
|
||||
Ox.range(10),
|
||||
function (value, index, array, callback) {
|
||||
setTimeout(function() {
|
||||
callback(+new Date() - time);
|
||||
}, Ox.random(1000));
|
||||
},
|
||||
function(results) {
|
||||
Ox.print(results);
|
||||
}
|
||||
);
|
||||
</script>
|
||||
@*/
|
||||
Ox.nonblockingMap = function() {
|
||||
asyncMap.apply(null, [Ox.nonblockingForEach].concat(Ox.toArray(arguments)));
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue