improve the start code for evented I/O

When evented I/O is being used, prevent event loop from terminating
at least until main() has returned.
This commit is contained in:
Andrew Kelley 2019-11-06 15:08:29 -05:00
parent c1e8fdf812
commit 913f7d0450
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -202,8 +202,8 @@ inline fn initEventLoopAndCallMain() u8 {
defer loop.deinit();
var result: u8 = undefined;
var frame: @Frame(callMain) = undefined;
_ = @asyncCall(&frame, &result, callMain);
var frame: @Frame(callMainAsync) = undefined;
_ = @asyncCall(&frame, &result, callMainAsync, loop);
loop.run();
return result;
}
@ -214,6 +214,13 @@ inline fn initEventLoopAndCallMain() u8 {
return @inlineCall(callMain);
}
fn callMainAsync(loop: *std.event.Loop) u8 {
// This prevents the event loop from terminating at least until main() has returned.
loop.beginOneEvent();
defer loop.finishOneEvent();
return callMain();
}
// This is not marked inline because it is called with @asyncCall when
// there is an event loop.
fn callMain() u8 {