Skip to content

Instantly share code, notes, and snippets.

@creationix creationix/test.js
Last active Dec 10, 2015

What would you like to do?
Example usage of runonce
var runOnce = require('uvrun').runOnce;
// Do something here, like make a server to keep the event loop busy
var TCP = process.binding('tcp_wrap').TCP;
var server = new TCP();
server.onconnection = function () {
server.bind("", 3000);
// Visualize each event loop tick using a custom event loop.
console.log("Waiting for events...");
do {
var ret = runOnce();
} while(ret);
// If the code gets here, there are no events left and node's built-in uv_run won't block.

This comment has been minimized.

Copy link

commented Jan 2, 2013

Interesting way to achieve "parallel" execution. Is that any different from process.nextTick regarding performance?


This comment has been minimized.

Copy link
Owner Author

commented Jan 7, 2013

It's not parallel, it's just a new event loop that blocks inside the built-in one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.