Created
October 3, 2014 22:43
-
-
Save bjouhier/0ddde2c67d847de276ee to your computer and use it in GitHub Desktop.
Crashes node-fibers 1.0.2, at least on OSX
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
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"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just ran across this -- was it ever resolved?