Created
September 23, 2016 10:09
-
-
Save realdecisions/2b4707827203c12e9e7af861695c87ef to your computer and use it in GitHub Desktop.
Coro::Channel multiplexer
This file contains hidden or 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
package Coro::MultiChannel; | |
#perl Coro::Channel multiplexer | |
use Coro; | |
use parent qw/Coro::Channel/; | |
sub CORO(){3} | |
sub new { | |
bless $_[0]->SUPER::new($_[1]); | |
} | |
sub attach { | |
my $coro; | |
$coro = async { | |
while(defined($_ = $_[1]->get)){ | |
push @{$_[0][Coro::Channel::DATA]}, $_; | |
Coro::Semaphore::up $_[0][Coro::Channel::SGET]; | |
Coro::Semaphore::down $_[0][Coro::Channel::SPUT]; | |
} | |
delete $_[0][CORO]{$coro}; | |
Coro::Semaphore::adjust $_[0][Coro::Channel::SGET], 1_000_000_000 unless keys %{$_[0][CORO]}; | |
1; | |
} @_; | |
$_[0][CORO]{$coro} = $coro; | |
1; | |
} | |
sub put { | |
#It does not make sense | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment