| ... | @@ -202,8 +202,8 @@ inline fn initEventLoopAndCallMain() u8 { | ... | @@ -202,8 +202,8 @@ inline fn initEventLoopAndCallMain() u8 { |
| 202 | defer loop.deinit(); | 202 | defer loop.deinit(); |
| 203 | | 203 | |
| 204 | var result: u8 = undefined; | 204 | var result: u8 = undefined; |
| 205 | var frame: @Frame(callMain) = undefined; | 205 | var frame: @Frame(callMainAsync) = undefined; |
| 206 | _ = @asyncCall(&frame, &result, callMain); | 206 | _ = @asyncCall(&frame, &result, callMainAsync, loop); |
| 207 | loop.run(); | 207 | loop.run(); |
| 208 | return result; | 208 | return result; |
| 209 | } | 209 | } |
| ... | @@ -214,6 +214,13 @@ inline fn initEventLoopAndCallMain() u8 { | ... | @@ -214,6 +214,13 @@ inline fn initEventLoopAndCallMain() u8 { |
| 214 | return @inlineCall(callMain); | 214 | return @inlineCall(callMain); |
| 215 | } | 215 | } |
| 216 | | 216 | |
| | 217 | fn callMainAsync(loop: *std.event.Loop) u8 { |
| | 218 | // This prevents the event loop from terminating at least until main() has returned. |
| | 219 | loop.beginOneEvent(); |
| | 220 | defer loop.finishOneEvent(); |
| | 221 | return callMain(); |
| | 222 | } |
| | 223 | |
| 217 | // This is not marked inline because it is called with @asyncCall when | 224 | // This is not marked inline because it is called with @asyncCall when |
| 218 | // there is an event loop. | 225 | // there is an event loop. |
| 219 | fn callMain() u8 { | 226 | fn callMain() u8 { |