Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use 5.14.0;
- use warnings;
- use Coro;
- use EV;
- use AnyEvent;
- use Coro::AnyEvent;
- use Coro::Handle;
- my $line1;
- my $line2;
- my $worker = async {
- my $fh = unblock \*STDIN;
- eval {
- $line1 = $fh->readline;
- };
- if ($@) {
- $line1 = "interrupted reading first line: $@";
- }
- eval {
- $line2 = $fh->readline;
- };
- if ($@) {
- $line2 = "interrupted reading next line: $@";
- }
- };
- Coro::AnyEvent::sleep(1);
- $worker->throw("interrupt\n");
- $worker->ready;
- $worker->join;
- print $line1, $line2;
- __END__
- If nothing is entered on stdin in the first second, we expect $line1 to be
- "interrupted reading first line: interrupt\n"
- but also $line2 ends up as
- "interrupted reading next line: recursive invocation of readable_ev or writable_ev (concurrent Coro::Handle calls on same handle?), detected at /usr/lib/perl5/Coro/Handle.pm line 551.\n"
- I appreciate you can't use the same Coro::Handle instance simultaneously from two coroutines, but here only one coroutine is using it.
- This is a simplified test case. The use of throw() is desired for other reasons; I know there are other possible approaches in this example.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement