Skip to content

Instantly share code, notes, and snippets.

@ityonemo
Created December 6, 2020 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ityonemo/1b7a715757d0395fd4f0973962e50816 to your computer and use it in GitHub Desktop.
Save ityonemo/1b7a715757d0395fd4f0973962e50816 to your computer and use it in GitHub Desktop.
awaiting resumed ??? example
const std = @import("std");
const print = std.debug.print;
var yielded = false;
fn yield() void {
yielded = true;
suspend;
}
fn scheduler() i32 {
yield();
return 47;
}
pub fn main() void {
var frame = async scheduler();
var cycle: i32 = 0;
while (yielded) {
yielded = false;
print("cycle {}\n", .{cycle});
resume frame;
cycle += 1;
}
var result = nosuspend await frame;
print("result: {}\n", .{result});
}
const std = @import("std");
const print = std.debug.print;
var yielded = false;
fn yield() void {
yielded = true;
suspend;
}
fn scheduler() i32 {
yielded = true;
suspend;
return 47;
}
pub fn main() void {
var frame = async scheduler();
var cycle: i32 = 0;
while (yielded) {
yielded = false;
print("cycle {}\n", .{cycle});
resume frame;
cycle += 1;
}
var result = nosuspend await frame;
print("result: {}\n", .{result});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment