… | |
… | |
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 | |
… | |
… | |
23 | } |
24 | } |
24 | |
25 | |
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 | if ($self->{conns} >= 0) { |
29 | |
30 | while(@{$self->{wait}}) { |
30 | (pop @{$self->{wait}})->wake if @{$self->{wait}}; |
31 | my $transfer = shift @{$self->{wait}}; |
|
|
32 | if ($transfer) { |
|
|
33 | $transfer->wake; |
|
|
34 | last; |
|
|
35 | } |
|
|
36 | } |
|
|
37 | } |
31 | } |
38 | } |
32 | |
39 | |
33 | sub waiters { |
40 | sub waiters { |
34 | map $_->[1], @{$_[0]{wait}}; |
41 | map $_->[1], @{$_[0]{wait}}; |
35 | } |
42 | } |
… | |
… | |
40 | |
47 | |
41 | sub try { |
48 | sub try { |
42 | my $self = shift; |
49 | my $self = shift; |
43 | my $timeout = Coro::Timer::timeout $_[0]; |
50 | my $timeout = Coro::Timer::timeout $_[0]; |
44 | |
51 | |
45 | Coro::schedule; |
52 | $self->[2] or Coro::schedule; |
46 | |
53 | |
47 | return $self->[2]; |
54 | return $self->[2]; |
48 | } |
55 | } |
49 | |
56 | |
50 | sub wake { |
57 | sub wake { |