-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Support for multiple event loops #7323
Comments
What's the point of using a second event loop, if it blocks the first one? |
The same as |
This is an interesting topic, could you touch a bit more on the topic of how it could benefit proper node development though? |
@jimmiehansson well, as I have already mentioned it is intended for same set of use cases as existing "sync" functions. That is, initialization and scripting, to name some. Let's say we have a configuration step that pulls some data from file system synchronously. There is no easy way to plug in some other source of that data, because most of IO doesn't have synchronous capabilities. With proposed API we could just do: var loop = require('event_loop').create();
function configure () {
var data;
require('event_loop').create().run(function () {
getDataSomehow(function (err, res) {
if (err) throw err;
data = res;
});
});
return data;
} You can think of this as an "inlined" Anyway, I don't think this will ever happen, because: 1. no one cares; 2. you definitely can live without it, especially with generators and stuff; 3. it requires huge refactoring with possible performance drop. |
@vkurchatkin Its an interesting idea. But I do have to agree, I highly doubt it will be brought to the table. Thanks for the explanation! |
Currently only
uv_default_loop()
is used, but since now loop is obtained fromEnv
it could be changed for something else. This can be used implement custom blocking IO using existing non-blocking primitives.The API can be derived from
domain
, because of the similarity (that is, grouping async operations):Uncaught errors could be thrown from
loop.run
. Obviously, some changes innextTick
are required, as it should have queue per each event loop.The text was updated successfully, but these errors were encountered: