… | |
… | |
25 | use Coro::Process (); |
25 | use Coro::Process (); |
26 | |
26 | |
27 | $VERSION = 0.01; |
27 | $VERSION = 0.01; |
28 | |
28 | |
29 | sub new { |
29 | sub new { |
30 | bless [$_[1]], $_[0]; |
30 | bless [defined $_[1] ? $_[1] : 1], $_[0]; |
31 | } |
31 | } |
32 | |
32 | |
33 | sub down { |
33 | sub down { |
34 | my $self = shift; |
34 | my $self = shift; |
35 | while ($self->[0] <= 0) { |
35 | while ($self->[0] <= 0) { |
… | |
… | |
39 | --$self->[0]; |
39 | --$self->[0]; |
40 | } |
40 | } |
41 | |
41 | |
42 | sub up { |
42 | sub up { |
43 | my $self = shift; |
43 | my $self = shift; |
44 | if (++@{$self->[1]} == 0) { |
44 | if (++$self->[0] > 0) { |
45 | (shift @{$self->[1]})->ready if @{$self->[1]}; |
45 | (shift @{$self->[1]})->ready if @{$self->[1]}; |
46 | } |
46 | } |
47 | } |
47 | } |
48 | |
48 | |
49 | sub try { |
49 | sub try { |