react {
whenever Supply.interval(0.5) {
.say;
}
}
react {
whenever Supply.interval(0.5) {
done if $_ > 3;
.say;
}
}
react {
whenever Supply.from-list('a' .. 'e') {
.say;
}
}
react {
whenever Supply.interval(0.5) {
say now;
}
whenever Promise.in(3) {
done;
}
}
my $socket = await IO::Socket::Async.connect:
'moarvm.org', 80;
await $socket.print:
"GET / HTTP/1.0\r\nHost: moarvm.org\r\n\r\n";
react {
whenever $socket -> $chars {
print $chars;
}
}
my $file = ‘foo’.IO;
spurt $file, “and\nCamelia\n♡\nme\n”;
my $proc = Proc::Async.new: :w, ‘tac’, ‘--’, $file, ‘-’;
react {
whenever $proc.stdout.lines {
say ‘line: ’, $_
}
whenever $proc.stderr {
say ‘stderr: ’, $_
}
whenever $proc.ready {
say ‘PID: ’, $_
}
whenever $proc.start {
say ‘Proc finished: exitcode=’, .exitcode, ‘ signal=’, .signal;
done
}
whenever $proc.print: “I\n♥\nCamelia\n” {
$proc.close-stdin
}
whenever signal(SIGTERM).merge: signal(SIGINT) {
once {
say ‘Signal received, asking the process to stop’;
$proc.kill;
whenever signal($_).zip: Promise.in(2).Supply {
say ‘Kill it!’;
$proc.kill: SIGKILL
}
}
}
whenever Promise.in(5) {
say ‘Timeout. Asking the process to stop’;
$proc.kill;
whenever Promise.in(2) {
say ‘Timeout. Forcing the process to stop’;
$proc.kill: SIGKILL
}
}
}
say ‘Program finished’;
my $proc = Proc::Async.new("tail", "-f", "/var/log/system.log", :out);
react {
whenever $proc.stdout.lines {
say ‘line: ’, $_
}
whenever $proc.stderr {
say ‘stderr: ’, $_
}
whenever $proc.ready {
say ‘PID: ’, $_
}
whenever $proc.start {
say ‘Proc finished: exitcode=’, .exitcode, ‘ signal=’, .signal;
done
}
whenever signal(SIGTERM).merge: signal(SIGINT) {
once {
say ‘Signal received, asking the process to stop’;
$proc.kill;
whenever signal($_).zip: Promise.in(2).Supply {
say ‘Kill it!’;
$proc.kill: SIGKILL
}
}
}
}
say ‘Program finished’;