pub fn next(batch: *Batch) ?Completion batch: *Batch653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670 pub fn next(batch: *Batch) ?Completion {
const index = batch.completed.head;
if (index == .none) return null;
const storage = &batch.storage[index.toIndex()];
const completion = storage.completion;
const next_index = completion.node.next;
batch.completed.head = next_index;
if (next_index == .none) batch.completed.tail = .none;
const tail_index = batch.unused.tail;
switch (tail_index) {
.none => batch.unused.head = index,
else => batch.storage[tail_index.toIndex()].unused.next = index,
}
storage.* = .{ .unused = .{ .prev = tail_index, .next = .none } };
batch.unused.tail = index;
return .{ .index = index.toIndex(), .result = completion.result };
}
After calling
awaitAsync,awaitConcurrent, orcancel, this function iterates over the completed operations.Each completion returned from this function dequeues from the
Batch. It is not required to dequeue all completions before awaiting again.