… | |
… | |
8 | } |
8 | } |
9 | |
9 | |
10 | sub start_transfer { |
10 | sub start_transfer { |
11 | my $self = shift; |
11 | my $self = shift; |
12 | |
12 | |
13 | my $trans = bless [ $self, $Coro::current ], transfer::; |
13 | my $trans = bless [ $self ], 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 | Scalar::Util::weaken($self->{wait}[-1]); |
18 | |
18 | |
… | |
… | |
24 | } |
24 | } |
25 | |
25 | |
26 | sub wake_next { |
26 | sub wake_next { |
27 | my $self = shift; |
27 | my $self = shift; |
28 | |
28 | |
29 | return unless $self->{conns} >= 0; |
29 | if ($self->{conns} >= 0) { |
30 | |
|
|
31 | if (@{$self->{wait}}) { |
30 | while(@{$self->{wait}}) { |
32 | while() { |
|
|
33 | my $transfer = shift @{$self->{wait}}; |
31 | my $transfer = shift @{$self->{wait}}; |
34 | if ($transfer) { |
32 | if ($transfer) { |
35 | $transfer->wake; |
33 | $transfer->wake; |
36 | last; |
34 | last; |
37 | } |
35 | } |
… | |
… | |
49 | |
47 | |
50 | sub try { |
48 | sub try { |
51 | my $self = shift; |
49 | my $self = shift; |
52 | my $timeout = Coro::Timer::timeout $_[0]; |
50 | my $timeout = Coro::Timer::timeout $_[0]; |
53 | |
51 | |
|
|
52 | unless ($self->[2]) { |
|
|
53 | local $self->[1] = $Coro::current; |
54 | Coro::schedule; |
54 | Coro::schedule; |
|
|
55 | } |
55 | |
56 | |
56 | return $self->[2]; |
57 | return $self->[2]; |
57 | } |
58 | } |
58 | |
59 | |
59 | sub wake { |
60 | sub wake { |
60 | my $self = shift; |
61 | my $self = shift; |
61 | $self->[2] = 1; |
62 | $self->[2] = 1; |
62 | $self->[1]->ready; |
63 | ref $self->[1] and $self->[1]->ready; |
63 | } |
64 | } |
64 | |
65 | |
65 | sub DESTROY { |
66 | sub DESTROY { |
66 | my $self = shift; |
67 | my $self = shift; |
67 | $self->[0]{conns}++; |
68 | $self->[0]{conns}++; |