| author | |
| committer | |
| log | 456a244d62df62940f4d860cd9f57b40d563ca96 |
| tree | 24f2b2abba0032003141b517cd782f0520fcd089 |
| parent | e24cc2e77b741fe49e738acc497fbedf2998008c |
2 files changed, 9 insertions(+), 9 deletions(-)
std/event/future.zig+5-6| ... | ... | @@ -97,28 +97,27 @@ test "std.event.Future" { |
| 97 | 97 | loop.run(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | async fn testFuture(loop: *Loop) void { | |
| 100 | fn testFuture(loop: *Loop) void { | |
| 101 | 101 | var future = Future(i32).init(loop); |
| 102 | 102 | |
| 103 | 103 | var a = async waitOnFuture(&future); |
| 104 | 104 | var b = async waitOnFuture(&future); |
| 105 | var c = async resolveFuture(&future); | |
| 105 | resolveFuture(&future); | |
| 106 | 106 | |
| 107 | // TODO make this work: | |
| 107 | // TODO https://github.com/ziglang/zig/issues/3077 | |
| 108 | 108 | //const result = (await a) + (await b); |
| 109 | 109 | const a_result = await a; |
| 110 | 110 | const b_result = await b; |
| 111 | 111 | const result = a_result + b_result; |
| 112 | 112 | |
| 113 | await c; | |
| 114 | 113 | testing.expect(result == 12); |
| 115 | 114 | } |
| 116 | 115 | |
| 117 | async fn waitOnFuture(future: *Future(i32)) i32 { | |
| 116 | fn waitOnFuture(future: *Future(i32)) i32 { | |
| 118 | 117 | return future.get().*; |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | async fn resolveFuture(future: *Future(i32)) void { | |
| 120 | fn resolveFuture(future: *Future(i32)) void { | |
| 122 | 121 | future.data = 6; |
| 123 | 122 | future.resolve(); |
| 124 | 123 | } |
std/event/loop.zig+4-3| ... | ... | @@ -149,14 +149,15 @@ pub const Loop = struct { |
| 149 | 149 | .overlapped = ResumeNode.overlapped_init, |
| 150 | 150 | }, |
| 151 | 151 | }; |
| 152 | // We need an extra one of these in case the fs thread wants to use onNextTick | |
| 152 | // We need at least one of these in case the fs thread wants to use onNextTick | |
| 153 | const extra_thread_count = thread_count - 1; | |
| 154 | const resume_node_count = std.math.max(extra_thread_count, 1); | |
| 153 | 155 | self.eventfd_resume_nodes = try self.allocator.alloc( |
| 154 | 156 | std.atomic.Stack(ResumeNode.EventFd).Node, |
| 155 | thread_count, | |
| 157 | resume_node_count, | |
| 156 | 158 | ); |
| 157 | 159 | errdefer self.allocator.free(self.eventfd_resume_nodes); |
| 158 | 160 | |
| 159 | const extra_thread_count = thread_count - 1; | |
| 160 | 161 | self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count); |
| 161 | 162 | errdefer self.allocator.free(self.extra_threads); |
| 162 | 163 |