mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-21 21:53:11 -05:00
Added ex91 - closing in on async!
This commit is contained in:
parent
4c7eebbbfc
commit
49ce260748
3 changed files with 55 additions and 0 deletions
|
@ -443,6 +443,10 @@ const exercises = [_]Exercise{
|
|||
.main_file = "090_async7.zig",
|
||||
.output = "beef? BEEF!",
|
||||
},
|
||||
.{
|
||||
.main_file = "091_async8.zig",
|
||||
.output = "ABCDEF",
|
||||
},
|
||||
};
|
||||
|
||||
/// Check the zig version to make sure it can compile the examples properly.
|
||||
|
|
35
exercises/091_async8.zig
Normal file
35
exercises/091_async8.zig
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// You have doubtless noticed that 'suspend' requires a block
|
||||
// expression like so:
|
||||
//
|
||||
// suspend {}
|
||||
//
|
||||
// The suspend block executes when a function suspends. To get
|
||||
// sense for when this happens, please make the following
|
||||
// program print the string
|
||||
//
|
||||
// "ABCDEF"
|
||||
//
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
pub fn main() void {
|
||||
print("A", .{});
|
||||
|
||||
var frame = async suspendable();
|
||||
|
||||
print("X", .{});
|
||||
|
||||
resume frame;
|
||||
|
||||
print("F", .{});
|
||||
}
|
||||
|
||||
fn suspendable() void {
|
||||
print("X", .{});
|
||||
|
||||
suspend {
|
||||
print("X", .{});
|
||||
}
|
||||
|
||||
print("X", .{});
|
||||
}
|
16
patches/patches/091_async8.patch
Normal file
16
patches/patches/091_async8.patch
Normal file
|
@ -0,0 +1,16 @@
|
|||
20c20
|
||||
< print("X", .{});
|
||||
---
|
||||
> print("D", .{});
|
||||
28c28
|
||||
< print("X", .{});
|
||||
---
|
||||
> print("B", .{});
|
||||
31c31
|
||||
< print("X", .{});
|
||||
---
|
||||
> print("C", .{});
|
||||
34c34
|
||||
< print("X", .{});
|
||||
---
|
||||
> print("E", .{});
|
Loading…
Reference in a new issue