Created
April 15, 2011 18:14
-
-
Save jfd/922174 to your computer and use it in GitHub Desktop.
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
require("./fibers"); | |
var count = 0; | |
var fib1 = Fiber(function() { | |
var runme = true; | |
while (runme) { | |
Fiber.yield(); | |
var msg = fib1.mailbox.shift(); | |
if (msg[0] == "end") { | |
runme = false; | |
} else { | |
fib2.run(); | |
} | |
} | |
}); | |
fib1.mailbox = []; | |
var fib2 = Fiber(function() { | |
var runme = true; | |
while (runme) { | |
if (count++ < 100000) { | |
fib1.mailbox.push(["Hello world"]); | |
process.nextTick(function() { | |
fib1.run(); | |
}); | |
} else { | |
fib1.mailbox.push(["end"]); | |
process.nextTick(function() { | |
fib1.run(); | |
}); | |
runme = false; | |
} | |
Fiber.yield(); | |
} | |
}); | |
fib1.run(); | |
fib2.run(); |
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 count = 0; | |
var fib1 = function() { | |
if (fib1.runme) { | |
var msg = fib1.mailbox.shift(); | |
if (msg[0] == "end") { | |
fib1.runme = false; | |
} else { | |
process.nextTick(fib2); | |
} | |
} | |
}; | |
fib1.runme = true; | |
fib1.mailbox = []; | |
var fib2 = function() { | |
if (count++ < 100000) { | |
fib1.mailbox.push(["Hello world"]); | |
process.nextTick(fib1); | |
} else { | |
fib1.mailbox.push(["end"]); | |
process.nextTick(fib1); | |
fib2.runme = false; | |
} | |
}; | |
fib2.runme = true; | |
process.nextTick(fib2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment