diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-04-03 19:32:53 +0200 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-04-03 19:32:53 +0200 |
| commit | 5307b2a338a92130bc498fb1dc7d21a9fd1b0db4 (patch) | |
| tree | 51279ca4fbd7bd90294dd563640c12a8c25c79c6 /exercises/088_async5.zig | |
| parent | 3056a2b5442f2f1ec58db3f3493109064ad2a2a5 (diff) | |
| parent | f6a6798c8b6b813bd2ceee81db276e05327a76e0 (diff) | |
Merge pull request 'revival of the async-io functions' (#383) from asyncIo into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/383
Diffstat (limited to 'exercises/088_async5.zig')
| -rw-r--r-- | exercises/088_async5.zig | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/exercises/088_async5.zig b/exercises/088_async5.zig deleted file mode 100644 index 759a920..0000000 --- a/exercises/088_async5.zig +++ /dev/null @@ -1,48 +0,0 @@ -// -// Sure, we can solve our async value problem with a global -// variable. But this hardly seems like an ideal solution. -// -// So how do we REALLY get return values from async functions? -// -// The 'await' keyword waits for an async function to complete -// and then captures its return value. -// -// fn foo() u32 { -// return 5; -// } -// -// var foo_frame = async foo(); // invoke and get frame -// var value = await foo_frame; // await result using frame -// -// The above example is just a silly way to call foo() and get 5 -// back. But if foo() did something more interesting such as wait -// for a network response to get that 5, our code would pause -// until the value was ready. -// -// As you can see, async/await basically splits a function call -// into two parts: -// -// 1. Invoke the function ('async') -// 2. Getting the return value ('await') -// -// Also notice that a 'suspend' keyword does NOT need to exist in -// a function to be called in an async context. -// -// Please use 'await' to get the string returned by -// getPageTitle(). -// -const print = @import("std").debug.print; - -pub fn main() void { - var myframe = async getPageTitle("http://example.com"); - - var value = ??? - - print("{s}\n", .{value}); -} - -fn getPageTitle(url: []const u8) []const u8 { - // Please PRETEND this is actually making a network request. - _ = url; - return "Example Title."; -} |
