| 356 | | - $obj.wake_on_either_readable_or_writable_or_passed_time(3); # fixme fixme |
| 357 | | - $obj.wake_on:{.readable} # busy wait, probably |
| 358 | | |
| 359 | | my @a is Array::Chan = 1..Inf; |
| 360 | | async { @a.push(1) }; |
| 361 | | async { @a.blocking_shift({ ... }) }; |
| 362 | | async { @a.unshift({ ... }) }; |
| 363 | | |
| | 354 | $obj.wake_on_either_readable_or_writable_or_passed_time(3); # fixme fixme |
| | 355 | $obj.wake_on:{.readable} # busy wait, probably |
| | 356 | |
| | 357 | my @a is Array::Chan = 1..Inf; |
| | 358 | async { @a.push(1) }; |
| | 359 | async { @a.blocking_shift({ ... }) }; |
| | 360 | async { @a.unshift({ ... }) }; |
| 593 | | =head3 braindump of coro meeting by Liz and Autri, more to follow |
| 594 | | |
| 595 | | - Coros are _like_ processes |
| 596 | | |
| 597 | | |
| 598 | | coro foo ($x) { |
| 599 | | yield $x; |
| 600 | | yield $x+2; |
| 601 | | cleanup(); |
| 602 | | while (2) { |
| 603 | | while (1) { |
| 604 | | &?SUB.kill; # seppuku |
| 605 | | } |
| 606 | | } |
| 607 | | } # implicit falloff return + return() means start over without yielding |
| 608 | | # return() means yielding and restart + no implicit falloff (I LIKE THIS) |
| 609 | | |
| 610 | | foo(4); # and that's all she wrote |
| 611 | | |
| 612 | | sub foo { |
| 613 | | return undef if rand; |
| 614 | | ... |
| 615 | | } |
| 616 | | |
| 617 | | use overload { |
| 618 | | '&{}' => sub { ... } |
| 619 | | } |
| 620 | | |
| 621 | | class Coro is Conc::Multiplex does Code { |
| 622 | | method postcircumfix:<( )> { |
| 623 | | # start the thread, block stuff (we are in the caller's context) |
| 624 | | } |
| 625 | | } |
| 626 | | |
| 627 | | class Hash is extended { |
| 628 | | method postcircumfix:<( )> (&self: *@_) { |
| 629 | | &self = self.start(@_); |
| 630 | | } |
| 631 | | method start { |
| 632 | | # remember self |
| 633 | | # upon return() or normal falloff, restore self |
| 634 | | } |
| 635 | | } |
| 636 | | |
| 637 | | %*ENV(123); |
| 638 | | |
| 639 | | |
| 640 | | # continuation coros |
| 641 | | multi foo () { ...no rebinding... } |
| 642 | | multi foo ($x) { ...rebinding... } |
| 643 | | |
| 644 | | &foo.kill; |
| 645 | | |
| 646 | | |
| 647 | | my $first_ret = zoro( type => <even> ); |
| 648 | | &zoro.variant(:type<even>).kill; |
| 649 | | &zoro.variant(type => 'even').kill; |
| 650 | | |
| 651 | | zoro( type => <odd> ); |
| 652 | | |
| 653 | | zoro( even => 1 ); |
| 654 | | zoro( odd => 1 ); |
| 655 | | |
| 656 | | multi coro zoro ($type where 'even') {} |
| 657 | | multi coro zoro ($type where 'odd') {} |
| 658 | | |
| 659 | | multi coro zoro ($even is named) {} |
| 660 | | multi coro zoro ($odd is named) {} |
| 661 | | |
| 662 | | |
| 663 | | # iblech's thoughts: |
| 664 | | # Coroutine parameters should never be rebound. Instead, yield(...)s return |
| 665 | | # value is an Arglist object containing the new arguments: |
| 666 | | coro bar ($a, $b) { |
| 667 | | ...; |
| 668 | | my $new_set_of_args = yield(...); |
| 669 | | my $sum_of_old_a_and_new_a = $a + $new_set_of_args<$a>; |
| 670 | | ...; |
| 671 | | } |
| 672 | | bar(42, 23); # $a is 42, $b is 23 |
| 673 | | bar(17, 19); # $a still 42, $b still 19, |
| | 582 | =head2 See also |
| | 583 | |
| | 584 | =over |
| | 585 | |
| | 586 | =item * |
| | 587 | |
| | 588 | L<S16/Interprocess Communication> |
| | 589 | |
| | 590 | =item * |
| | 591 | |
| | 592 | L<S16/I/O Considerations> |
| | 593 | |
| | 594 | =item * |
| | 595 | |
| | 596 | L<S16/File Descriptors> |
| | 597 | |
| | 598 | =item * |
| | 599 | |
| | 600 | L<S16/Sockets> |
| | 601 | |
| | 602 | =back |