Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const std = @import("std");
- const warn = std.debug.warn;
- const allocator = std.debug.global_allocator;
- fn foo(n: u32) u32 {
- return n * 2;
- }
- pub fn main() !void {
- var handle = try async<allocator> slow_action();
- var mapped = try async<allocator> map(u32, u32, handle, foo);
- resume mapped;
- }
- async fn map(comptime T: type, comptime U: type, p: promise-> T, f: fn(T) U) U {
- var result = await p;
- return f(result);
- }
- async fn slow_action() u32 {
- var n: usize = 0;
- while(n < 10): (n += 1) {
- suspend;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement