Advertisement
Doc_Holliwood

Untitled

Aug 19th, 2019
2,721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.49 KB | None | 0 0
  1.  
  2. sub asynchronize(Supply $s) {
  3.     #"asynchronize".say;
  4.     supply {
  5.         whenever Promise.kept {
  6.             #"asynchronize whenever".say;
  7.             whenever $s { "asynchronize whenever emit".say;.emit }
  8.         }
  9.     }
  10. }
  11.  
  12. react {
  13.     my $i = 0;
  14.     my $supply1 = supply { loop { await Promise.in(3); done if $i++> 5; emit("1") } }
  15.     my $supply2 = supply { loop { await Promise.in(1); done if $i++> 5; emit("2") } }
  16.  
  17.     whenever asynchronize $supply2 -> $x { $x.print }
  18.     whenever asynchronize $supply1 -> $x { $x.print }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement