Perl6多线程4: Promise allof / anyof

allof   : 所有代码块执行完成后才退出

anyof :只要有一个代码块执行完后就马上退出

 

要配合 await 一起用:

my $p = start {say 'a'};
my $p1 = start {sleep 4;say 'b';}
my $all = Promise.anyof($p,$p1);
await $all;

这个代码, 只会打印出: a

 

my $p = start {say 'a'};
my $p1 = start {sleep 4;say 'b';}
my $all = Promise.allof($p,$p1);
await $all;

这个代码会打印出: a, b

 

posted on 2017-08-27 15:32  Perl6  阅读(219)  评论(0编辑  收藏  举报

导航