Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created February 1, 2023 01:56
Show Gist options
  • Save bradclawsie/c7ccc5d2cf416e813521da185e133ac5 to your computer and use it in GitHub Desktop.
Save bradclawsie/c7ccc5d2cf416e813521da185e133ac5 to your computer and use it in GitHub Desktop.
futures.pl
#!/usr/bin/env perl
use v5.36;
use Future::AsyncAwait;
use Future::IO;
use experimental qw( signatures );
async sub f($v) {
say 'start of f' . $v;
say time;
say 'a' . $v;
await Future::IO->sleep(1);
say 'after sleep in f' . $v;
say time;
say 'b' . $v;
return time;
}
my $fx = f('x');
my $fy = f('y');
say $fx->get;
say $fy->get;
1;
__END__
@bradclawsie
Copy link
Author

sample output:

start of fx
1675216592
ax
start of fy
1675216592
ay
after sleep in fx
1675216593
bx
after sleep in fy
1675216593
by
1675216593
1675216593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment