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
var path = require('path') | |
, fs = require('fs') | |
, Sync = require('sync') | |
// Return a future which just pauses for a certain amount of time | |
function realish (p) { | |
return path.resolve(path.dirname(fs.readlink.sync(fs, p))) | |
} |
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
function someAsyncFunction(param, callback) { | |
setTimeout(function(){ | |
callback(null, param); // result | |
}, 100) | |
} | |
Function.prototype.sync = function(param) { | |
this(param, function(e, result) { | |
Fiber.run(result); // substitute result instead of yield, resume current Fiber |
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
someObject = { | |
myNewMethod : function(a, b) // <-- no callback | |
{ | |
console.log(Fiber.current); // Inside of fiber | |
if (a == 1) | |
throw "'a' cannot be 1"; // we can use throw here | |
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
/** | |
* Seq | |
*/ | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
var Seq = require('seq'); | |
Seq() | |
.seq(function () { | |
exec('whoami', this) |
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
/** | |
* Some existing external lib which you don't want to touch | |
*/ | |
var SomeModule = { | |
someAsyncFunction : function(callback) | |
{ | |
process.nextTick(function(){ | |
callback(null, 'result'); | |
}) |
NewerOlder