Edited at

synchronize.jsの注意点

More than 5 years have passed since last update.


sync_test.js

var sync = require('synchronize');

sync.fiber(function() {
try {
sync.await((function(defer) {
console.log("await 1 start");
setTimeout(function() {
console.log("await 1 end");
try {
sync.await((function(defer2) {
console.log("await 2 start");
setTimeout(function() {
console.log("await 2 end");
defer2(null, 'ok');
}, 1000);
})(sync.defer()));
console.log("await 2 over");
defer(null, "ok");
}
catch(e) {
console.log("await 2 error", e);
defer(e, null);
}
}, 1000);
})(sync.defer()));
} catch(e) {
console.log("await 1 error", e);
}
console.log("await 1 over");
});


% node sync_test.js

await 1 start
await 1 end
await 2 error [Error: no current Fiber, defer can'b be used without Fiber!]
await 1 error [Error: no current Fiber, defer can'b be used without Fiber!]
await 1 over

await中、再帰的とは言わないまでも、ネストした処理は書けないってことか。

多分fiberの限界なんだろうなぁ。。。