Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TickEventLoop() #46

Merged
merged 3 commits into from
Jan 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4800,21 +4800,23 @@ Local<Context> NewContext(Isolate* isolate,
}

inline static bool TickEventLoop(Environment & env) {
bool more = false;
uv_run(env.event_loop(), UV_RUN_NOWAIT);

if (uv_loop_alive(env.event_loop())) {
return true;
}

v8_platform.DrainVMTasks();

more = uv_loop_alive(env.event_loop());
if (more)
return more;
if (uv_loop_alive(env.event_loop())) {
return true;
}

EmitBeforeExit(&env);

// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env.event_loop());
return more;
return uv_loop_alive(env.event_loop());
}

// This is where the magic happens. Creates JavaScript context and a JS Environment, then runs the uv event loop until it is no longer alive (see TickEventLoop()), then tears down Env and context and returns JS exit code.
Expand Down