Promises/Deferred/Mojo.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 32 CC 1 SCAR 6.9
CC
1
Cov
0%
_notify_backend
2.0
_timeout
2.0
BEGIN
2.0
CRAP 2.0
1 package Promises::Deferred::Mojo;
2 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: An implementation of Promises in Perl
4 $Promises::Deferred::Mojo::VERSION = '1.05';
5 use strict;
6 use warnings;
7  
8 use Mojo::IOLoop;
9  
10 use parent 'Promises::Deferred';
11  
12  
13 # Before the next_tick-based approach used below, there was a
14 # Mojo::IOLoop->timer()-based approach for _notify_backend.
15 # The current code is more performant:
16  
17 # Original code (using the Mojo::Reactor::EV backend):
18 # Backend: Promises::Deferred::Mojo
19 # Benchmark: running one, two for at least 10 CPU seconds...
20 # one: 46 wallclock secs @ 758.45/s (n=8032)
21 # two: 44 wallclock secs @ 309.08/s (n=3097)
22  
23  
24 # New approach:
25 # Backend: Promises::Deferred::Mojo
26 # Benchmark: running one, two for at least 10 CPU seconds...
27 # one: 29 wallclock secs @ 1714.56/s (n=17197)
28 # two: 24 wallclock secs @ 1184.80/s (n=12156)
29  
30  
31  
32 sub _notify_backend {
33 my ( $self, $callbacks, $result ) = @_;
34 Mojo::IOLoop->next_tick(sub {
35 foreach my $cb (@$callbacks) {
36 $cb->(@$result);
37 }
38 });
39 }
40  
41 sub _timeout {
42 my ( $self, $timeout, $callback ) = @_;
43  
44 my $id = Mojo::IOLoop->timer( $timeout => $callback );
45
46 return sub { Mojo::IOLoop->remove($id) };
47 }
48  
49 1;
50  
51 __END__