Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bjouhier
Created October 3, 2014 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjouhier/0ddde2c67d847de276ee to your computer and use it in GitHub Desktop.
Save bjouhier/0ddde2c67d847de276ee to your computer and use it in GitHub Desktop.
Crashes node-fibers 1.0.2, at least on OSX
var Fiber = require("./build/Release/fibers").Fiber;
function wrap(fn, idx) {
function F() {
var cb = arguments[idx];
var that = this,
args = arguments;
Fiber(function () {
var val, err = null;
try {
val = fn.apply(that, args);
} catch (e) {
err = e;
} finally {
cb(err, val);
}
}).run();
};
return F;
}
function invoke(that, fn, args, idx) {
var fiber = Fiber.current;
var err, val, yielded = false;
args[idx] = function(e, v) {
if (!yielded) {
yielded = true;
err = e;
val = v;
} else {
if (e) {
fiber.throwInto(e);
} else {
fiber.run(v);
}
}
};
fn.apply(that, args);
if (yielded) return val;
yielded = true;
return Fiber.yield();
}
var immediately = wrap(function(ms) {
invoke(null, setImmediate, [null], 0);
}, 0);
function test(m, cb) {
if (m-- === 0) return cb();
immediately(function(err) {
if (err) return cb(err);
if (m % 1000 === 0) console.log(m + ": " + JSON.stringify(process.memoryUsage()));
test(m, cb);
});
}
test(100000000, function(err) {
if (err) throw err;
console.log("done");
})
@bcantrill
Copy link

Just ran across this -- was it ever resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment