Skip to content

Commit

Permalink
Merge pull request #46 from hpicgs/tick-event-loop-early-exit
Browse files Browse the repository at this point in the history
Improve TickEventLoop()
  • Loading branch information
luminosuslight authored Jan 30, 2018
2 parents 25211e6 + 2bb42fb commit ecee92a
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit ecee92a

Please sign in to comment.