Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
use v6.c;
# `mkfifo radio-fifo-in`
# `echo "foo" > radio-fifo-in`
# `echo "foo" > radio-fifo-in`
my &note = $*ERR.t ?? sub (*@s) { $*ERR.put: "\e[1m{@s.join('')}\e[0m" } !! sub (|c) { $*ERR.put: c };
my $command = Supplier.new;
my $fifo-state = Supplier.new;
my $fifo-file-name = radio-fifo-i;
say $fifo-file-name.IO.e;
enum FifoState <opend closed no-such-inode>;
{
start {
loop {
$fifo-state.emit(FifoState::no-such-inode) unless $fifo-file-name.IO.e;
my $fifo-in = open($fifo-file-name);
$fifo-state.emit: $fifo-in unless $fifo-in.defined;
$fifo-state.emit: FifoState::opend;
for $fifo-in.lines -> $line {
note got line;
$command.emit($line)
}
$fifo-state.emit: FifoState::closed;
}
}
}
react {
whenever $command {
say .Str;
done if //;
done if $++ > 10;
}
whenever $fifo-state -> $s {
with $s {
note fifo {.Str};
} else {
note .exception.^name, ': ', .exception.message;
}
}
whenever Supply.interval(1) {
say .Str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment