Created
December 11, 2016 21:46
-
-
Save jonathanstowe/6918de746aaddc9b299e397f5eedb8cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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