fix event loop regression on macos
parent
e24cc2e77b
commit
456a244d62
|
@ -97,28 +97,27 @@ test "std.event.Future" {
|
|||
loop.run();
|
||||
}
|
||||
|
||||
async fn testFuture(loop: *Loop) void {
|
||||
fn testFuture(loop: *Loop) void {
|
||||
var future = Future(i32).init(loop);
|
||||
|
||||
var a = async waitOnFuture(&future);
|
||||
var b = async waitOnFuture(&future);
|
||||
var c = async resolveFuture(&future);
|
||||
resolveFuture(&future);
|
||||
|
||||
// TODO make this work:
|
||||
// TODO https://github.com/ziglang/zig/issues/3077
|
||||
//const result = (await a) + (await b);
|
||||
const a_result = await a;
|
||||
const b_result = await b;
|
||||
const result = a_result + b_result;
|
||||
|
||||
await c;
|
||||
testing.expect(result == 12);
|
||||
}
|
||||
|
||||
async fn waitOnFuture(future: *Future(i32)) i32 {
|
||||
fn waitOnFuture(future: *Future(i32)) i32 {
|
||||
return future.get().*;
|
||||
}
|
||||
|
||||
async fn resolveFuture(future: *Future(i32)) void {
|
||||
fn resolveFuture(future: *Future(i32)) void {
|
||||
future.data = 6;
|
||||
future.resolve();
|
||||
}
|
||||
|
|
|
@ -149,14 +149,15 @@ pub const Loop = struct {
|
|||
.overlapped = ResumeNode.overlapped_init,
|
||||
},
|
||||
};
|
||||
// We need an extra one of these in case the fs thread wants to use onNextTick
|
||||
// We need at least one of these in case the fs thread wants to use onNextTick
|
||||
const extra_thread_count = thread_count - 1;
|
||||
const resume_node_count = std.math.max(extra_thread_count, 1);
|
||||
self.eventfd_resume_nodes = try self.allocator.alloc(
|
||||
std.atomic.Stack(ResumeNode.EventFd).Node,
|
||||
thread_count,
|
||||
resume_node_count,
|
||||
);
|
||||
errdefer self.allocator.free(self.eventfd_resume_nodes);
|
||||
|
||||
const extra_thread_count = thread_count - 1;
|
||||
self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count);
|
||||
errdefer self.allocator.free(self.extra_threads);
|
||||
|
||||
|
|
Loading…
Reference in New Issue