… | |
… | |
12 | |
12 | |
13 | my $trans = bless [ $self, $Coro::current ], transfer::; |
13 | my $trans = bless [ $self, $Coro::current ], transfer::; |
14 | Scalar::Util::weaken($trans->[0]); |
14 | Scalar::Util::weaken($trans->[0]); |
15 | |
15 | |
16 | push @{$self->{wait}}, $trans; |
16 | push @{$self->{wait}}, $trans; |
|
|
17 | Scalar::Util::weaken($self->{wait}[-1]); |
17 | |
18 | |
18 | if (--$self->{conns} >= 0) { |
19 | if (--$self->{conns} >= 0) { |
19 | $self->wake_next; |
20 | $self->wake_next; |
20 | } |
21 | } |
21 | |
22 | |
… | |
… | |
25 | sub wake_next { |
26 | sub wake_next { |
26 | my $self = shift; |
27 | my $self = shift; |
27 | |
28 | |
28 | return unless $self->{conns} >= 0; |
29 | return unless $self->{conns} >= 0; |
29 | |
30 | |
30 | (pop @{$self->{wait}})->wake if @{$self->{wait}}; |
31 | if (@{$self->{wait}}) { |
|
|
32 | while() { |
|
|
33 | my $transfer = shift @{$self->{wait}}; |
|
|
34 | if ($transfer) { |
|
|
35 | $transfer->wake; |
|
|
36 | last; |
|
|
37 | } |
|
|
38 | } |
|
|
39 | } |
31 | } |
40 | } |
32 | |
41 | |
33 | sub waiters { |
42 | sub waiters { |
34 | map $_->[1], @{$_[0]{wait}}; |
43 | map $_->[1], @{$_[0]{wait}}; |
35 | } |
44 | } |