mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 22:09:49 +00:00
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:
parent
c1e8fdf812
commit
913f7d0450
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user