Skip to content

Instantly share code, notes, and snippets.

@Jxck Jxck/next.js
Created Oct 17, 2012

Embed
What would you like to do?
非同期と next()
log = console.log.bind(console);
var assert = require('assert');
function test() {
var tests = Array.prototype.slice.call(arguments);
function next() {
if(!tests.length) return;
var args = Array.prototype.slice.call(arguments);
args.push(next);
var t = tests.shift();
t.apply(null, args);
};
next();
};
test(function(next) {
var a = 0;
a ++; log(a);
assert.equal(a, 1);
next(a, 1);
}, function(a, b, next) {
setTimeout(function() {
a += b; log(a);
assert.equal(a, 2);
next(a);
}, 200);
}, function(a, next) {
setTimeout(function() {
a ++; log(a);
assert.equal(a, 3);
next();
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.