Skip to content

Instantly share code, notes, and snippets.

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

Embed
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 () {
console.log("connection!");
};
server.bind("0.0.0.0", 3000);
server.listen(511);
// Visualize each event loop tick using a custom event loop.
console.log("Waiting for events...");
do {
var ret = runOnce();
console.log("tick", Date.now());
} while(ret);
// If the code gets here, there are no events left and node's built-in uv_run won't block.
@mantoni

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?

@creationix

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.