Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created December 11, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstowe/6918de746aaddc9b299e397f5eedb8cf to your computer and use it in GitHub Desktop.
Save jonathanstowe/6918de746aaddc9b299e397f5eedb8cf to your computer and use it in GitHub Desktop.
use v6.c;
my $supplier = Supplier.new;
start {
loop {
for ( 33 ... 126 ).map( { Buf.new($_) }) -> $c {
sleep 0.05;
$supplier.emit($c);
}
}
}
my $sig = signal(SIGPIPE).tap( -> $v {
$sig.close;
});
react {
whenever IO::Socket::Async.listen('localhost', 3333) -> $conn {
my $p = Promise.new;
CATCH {
when /'broken pipe'/ {
say "pipe exception";
if $p.status !~~ Kept {
$p.keep: "done";
}
}
}
my $write = $supplier.Supply.tap( -> $v {
if $p.status ~~ Planned {
$conn.write: $v;
}
else {
$write.close;
}
});
}
}
# vim: expandtab shiftwidth=4 ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment