daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Feb 24th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub run() {
  2.     my $count = 0;
  3.     my $supplier = Supplier.new;
  4.  
  5.     my $promise = start {
  6.         say "Starting loop...";
  7.         loop {
  8.             $count++;
  9.             $supplier.emit($count);
  10.  
  11.             if ($count == 10)
  12.             {
  13.                 say "We're done here";
  14.                 die "horribly";
  15.             }
  16.  
  17.             sleep 0.1;
  18.         }
  19.         CATCH {
  20.             # Without this default the entire program hangs when loop die()s
  21.             default { $supplier.quit($_) }
  22.         }
  23.     };
  24.  
  25.     return $supplier.Supply;
  26. }
  27.  
  28. sub MAIN {
  29.     say "About to start";
  30.     my $supply = run();
  31.  
  32.     say "Are we live?: " ~ $supply.live;
  33.     say "Started.. now waiting for data";
  34.     react {
  35.         whenever $supply {
  36.             say "Got value $_" ;
  37.             LAST { say "LAST" }
  38.             QUIT { say "QUIT" }
  39.         }
  40.     }
  41.  
  42.     sleep(10);
  43.     say "Done in main script";
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top