line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Role::Queued; |
2
|
3
|
|
|
3
|
|
3345
|
use Mojo::Base '-role'; |
|
3
|
|
|
|
|
186411
|
|
|
3
|
|
|
|
|
24
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = "1.15"; |
5
|
3
|
|
|
3
|
|
2924
|
use Mojo::UserAgent::Role::Queued::Queue; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
24
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has max_active => sub { shift->max_connections }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has job_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
|
|
|
|
|
|
|
if ($cb) { |
16
|
|
|
|
|
|
|
unless ($self->job_queue->callback) { |
17
|
|
|
|
|
|
|
my $this = $self; |
18
|
|
|
|
|
|
|
weaken $this; |
19
|
|
|
|
|
|
|
$self->job_queue->callback(sub { $this->$orig(@_) }); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
unless ($self->job_queue->has_subscribers('queue_empty')) { |
22
|
|
|
|
|
|
|
my $this = $self; |
23
|
|
|
|
|
|
|
weaken $this; |
24
|
|
|
|
|
|
|
$self->job_queue->on(queue_empty => sub { $this->emit('queue_empty') }); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
$self->job_queue->enqueue($tx, $cb); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
|
|
|
|
|
|
return $orig->($self, $tx); # Blocking calls skip the queue |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |