Created
November 15, 2014 15:09
-
-
Save freeart/3146ddeea166fee81c50 to your computer and use it in GitHub Desktop.
Sequence
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
function sequence(iterator, arrayList) { | |
this.iterator = iterator; | |
this.sequence = arrayList || []; | |
} | |
sequence.prototype.next = function (cb) { | |
var self = this; | |
if (self.sequence.length == 0){ | |
return setImmediate(cb, null, null); | |
} | |
setImmediate(function skip(self) { | |
self.iterator.next(function (err, cursor) { | |
if (cursor > self.sequence.length) { | |
self.iterator.reset(function () { | |
skip(self); | |
}) | |
} else { | |
cb(null, self.sequence[cursor - 1]) | |
} | |
}) | |
}, self); | |
} | |
module.exports = { | |
create: function (iterator, arrayList) { | |
return new sequence(iterator, arrayList) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment