Skip to content

Instantly share code, notes, and snippets.

@zostay
Created March 13, 2019 05:06
Show Gist options
  • Save zostay/9873b4af942f36abf4337da26df711d9 to your computer and use it in GitHub Desktop.
Save zostay/9873b4af942f36abf4337da26df711d9 to your computer and use it in GitHub Desktop.
use v6.d;
my Supplier $pinger .= new;
my Supplier $ponger .= new;
react {
say 'Beginning ping/pong...';
whenever $pinger.Supply.throttle: 1, 1 {
.say;
$ponger.emit: 'pong';
}
whenever $ponger.Supply.throttle: 1, 1 {
.say;
$pinger.emit: 'ping';
}
whenever Promise.in(10) {
exit 0;
}
$pinger.emit: 'ping';
}
use v6.d;
my Supplier::Preserving $pinger .= new;
my Supplier::Preserving $ponger .= new;
react {
ENTER {
say 'Beginning ping/pong...';
$pinger.emit: 'ping';
}
whenever $pinger.Supply.throttle: 1, 1 {
.say;
$ponger.emit: 'pong';
}
whenever $ponger.Supply.throttle: 1, 1 {
.say;
$pinger.emit: 'ping';
}
whenever Promise.in(10) {
exit 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment