line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Role::Queued; |
2
|
3
|
|
|
3
|
|
3957
|
use Mojo::Base '-role'; |
|
3
|
|
|
|
|
135043
|
|
|
3
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = "1.13"; |
5
|
3
|
|
|
3
|
|
2929
|
use Mojo::UserAgent::Role::Queued::Queue; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
29
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has max_active => sub { shift->max_connections }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has queue => sub { |
10
|
|
|
|
|
|
|
Mojo::UserAgent::Role::Queued::Queue->new(max_active => shift->max_active); |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
around start => sub { |
14
|
|
|
|
|
|
|
my ($orig, $self, $tx, $cb) = @_; |
15
|
|
|
|
|
|
|
$self->queue->callback(sub { $self->$orig(@_) }) |
16
|
|
|
|
|
|
|
unless ($self->queue->callback); |
17
|
|
|
|
|
|
|
if ($cb) { |
18
|
|
|
|
|
|
|
weaken $self; |
19
|
|
|
|
|
|
|
$tx->on(finish => sub { $self->queue->tx_finish(); }); |
20
|
|
|
|
|
|
|
$self->queue->on(queue_empty => sub { $self->emit('queue_empty') }); |
21
|
|
|
|
|
|
|
$self->queue->enqueue([$tx, $cb]); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
|
|
|
|
|
|
return $orig->($self, $tx); # Blocking calls skip the queue |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |