Files
bun.sh/src/yield.zig
2022-04-03 16:35:09 -07:00

18 lines
434 B
Zig

pub fn Yield(comptime Type: anytype) type {
return struct {
frame: @Frame(Type) = undefined,
wait: bool = false,
pub fn set(this: *@This(), frame: anytype) void {
this.wait = true;
this.frame = frame.*;
}
pub fn maybeResume(this: *@This()) void {
if (!this.wait) return;
this.wait = false;
resume this.frame;
}
};
}