Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub run() {
- my $count = 0;
- my $supplier = Supplier.new;
- my $promise = start {
- say "Starting loop...";
- loop {
- $count++;
- $supplier.emit($count);
- if ($count == 10)
- {
- say "We're done here";
- die "horribly";
- }
- sleep 0.1;
- }
- CATCH {
- # Without this default the entire program hangs when loop die()s
- default { $supplier.quit($_) }
- }
- };
- return $supplier.Supply;
- }
- sub MAIN {
- say "About to start";
- my $supply = run();
- say "Are we live?: " ~ $supply.live;
- say "Started.. now waiting for data";
- react {
- whenever $supply {
- say "Got value $_" ;
- LAST { say "LAST" }
- QUIT { say "QUIT" }
- }
- }
- sleep(10);
- say "Done in main script";
- }
Advertisement
Add Comment
Please, Sign In to add comment