… | |
… | |
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 | |
19 | if (--$self->{conns} >= 0) { |
19 | --$self->{conns}; |
20 | $self->wake_next; |
20 | $self->wake_next; |
21 | } |
|
|
22 | |
21 | |
23 | $trans; |
22 | $trans; |
24 | } |
23 | } |
25 | |
24 | |
26 | sub wake_next { |
25 | sub wake_next { |
… | |
… | |
43 | |
42 | |
44 | package transfer; |
43 | package transfer; |
45 | |
44 | |
46 | use Coro::Timer (); |
45 | use Coro::Timer (); |
47 | |
46 | |
48 | sub try { |
|
|
49 | my $self = shift; |
|
|
50 | my $timeout = Coro::Timer::timeout $_[0]; |
|
|
51 | |
|
|
52 | unless ($self->[2]) { |
|
|
53 | local $self->[1] = $Coro::current; |
|
|
54 | Coro::schedule; |
|
|
55 | } |
|
|
56 | |
|
|
57 | return $self->[2]; |
|
|
58 | } |
|
|
59 | |
|
|
60 | sub wake { |
47 | sub wake { |
61 | my $self = shift; |
48 | my $self = shift; |
62 | $self->[2] = 1; |
49 | $self->[2] = 1; |
63 | ref $self->[1] and $self->[1]->ready; |
50 | ref $self->[1] and $self->[1]->ready; |
|
|
51 | } |
|
|
52 | |
|
|
53 | sub try { |
|
|
54 | my $self = shift; |
|
|
55 | |
|
|
56 | unless ($self->[2]) { |
|
|
57 | my $timeout = Coro::Timer::timeout $_[0]; |
|
|
58 | $self->[1] = $Coro::current; |
|
|
59 | |
|
|
60 | Coro::schedule; |
|
|
61 | |
|
|
62 | undef $self->[1]; |
|
|
63 | } |
|
|
64 | |
|
|
65 | return $self->[2]; |
64 | } |
66 | } |
65 | |
67 | |
66 | sub DESTROY { |
68 | sub DESTROY { |
67 | my $self = shift; |
69 | my $self = shift; |
68 | $self->[0]{conns}++; |
70 | $self->[0]{conns}++; |