… | |
… | |
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 | |
… | |
… | |
47 | |
47 | |
48 | sub try { |
48 | sub try { |
49 | my $self = shift; |
49 | my $self = shift; |
50 | my $timeout = Coro::Timer::timeout $_[0]; |
50 | my $timeout = Coro::Timer::timeout $_[0]; |
51 | |
51 | |
52 | $self->[2] or Coro::schedule; |
52 | unless ($self->[2]) { |
|
|
53 | local $self->[1] = $Coro::current; |
|
|
54 | Coro::schedule; |
|
|
55 | } |
53 | |
56 | |
54 | return $self->[2]; |
57 | return $self->[2]; |
55 | } |
58 | } |
56 | |
59 | |
57 | sub wake { |
60 | sub wake { |
58 | my $self = shift; |
61 | my $self = shift; |
59 | $self->[2] = 1; |
62 | $self->[2] = 1; |
60 | $self->[1]->ready; |
63 | ref $self->[1] and $self->[1]->ready; |
61 | } |
64 | } |
62 | |
65 | |
63 | sub DESTROY { |
66 | sub DESTROY { |
64 | my $self = shift; |
67 | my $self = shift; |
65 | $self->[0]{conns}++; |
68 | $self->[0]{conns}++; |