Created
December 6, 2020 00:41
-
-
Save ityonemo/1b7a715757d0395fd4f0973962e50816 to your computer and use it in GitHub Desktop.
awaiting resumed ??? example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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