| ... | @@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type { | ... | @@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type { |
| 1178 | io: Io, | 1178 | io: Io, |
| 1179 | group: Group, | 1179 | group: Group, |
| 1180 | queue: Queue(U), | 1180 | queue: Queue(U), |
| 1181 | outstanding: usize, | | |
| 1182 | | 1181 | |
| 1183 | const S = @This(); | 1182 | const S = @This(); |
| 1184 | | 1183 | |
| ... | @@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type { | ... | @@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type { |
| 1191 | .io = io, | 1190 | .io = io, |
| 1192 | .queue = .init(buffer), | 1191 | .queue = .init(buffer), |
| 1193 | .group = .init, | 1192 | .group = .init, |
| 1194 | .outstanding = 0, | | |
| 1195 | }; | 1193 | }; |
| 1196 | } | 1194 | } |
| 1197 | | 1195 | |
| ... | @@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type { | ... | @@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type { |
| 1235 | } | 1233 | } |
| 1236 | }; | 1234 | }; |
| 1237 | const context: Context = .{ .select = s, .args = args }; | 1235 | const context: Context = .{ .select = s, .args = args }; |
| 1238 | _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic); | | |
| 1239 | s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); | 1236 | s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); |
| 1240 | } | 1237 | } |
| 1241 | | 1238 | |
| ... | @@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type { | ... | @@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type { |
| 1276 | }; | 1273 | }; |
| 1277 | const context: Context = .{ .select = s, .args = args }; | 1274 | const context: Context = .{ .select = s, .args = args }; |
| 1278 | try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); | 1275 | try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); |
| 1279 | _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic); | | |
| 1280 | } | 1276 | } |
| 1281 | | 1277 | |
| 1282 | /// Blocks until another task of the select finishes. | 1278 | /// Blocks until another task of the select finishes. |
| 1283 | /// | 1279 | /// |
| 1284 | /// Asserts there is at least one more `outstanding` task. | | |
| 1285 | /// | | |
| 1286 | /// Not threadsafe. | 1280 | /// Not threadsafe. |
| 1287 | pub fn await(s: *S) Cancelable!U { | 1281 | pub fn await(s: *S) Cancelable!U { |
| 1288 | s.outstanding -= 1; | | |
| 1289 | return s.queue.getOne(s.io) catch |err| switch (err) { | 1282 | return s.queue.getOne(s.io) catch |err| switch (err) { |
| 1290 | error.Canceled => |e| return e, | 1283 | error.Canceled => |e| return e, |
| 1291 | error.Closed => unreachable, | 1284 | error.Closed => unreachable, |
| ... | @@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type { | ... | @@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type { |
| 1301 | /// | 1294 | /// |
| 1302 | /// Idempotent. Not threadsafe. | 1295 | /// Idempotent. Not threadsafe. |
| 1303 | pub fn cancel(s: *S) void { | 1296 | pub fn cancel(s: *S) void { |
| 1304 | s.outstanding = 0; | | |
| 1305 | s.group.cancel(s.io); | 1297 | s.group.cancel(s.io); |
| 1306 | } | 1298 | } |
| 1307 | }; | 1299 | }; |