Permalink
Browse files

improve all method in Mojo::Promise to resolve with no results if no …

…promises have been passed (closes #1193)
  • Loading branch information...
kraih committed Feb 13, 2018
1 parent c16a56a commit a18da70b19f47dc076782b107ac747076e2aa034
Showing with 12 additions and 18 deletions.
  1. +4 −0 Changes
  2. +0 −17 lib/Mojo/IOLoop/Delay.pm
  3. +1 −1 lib/Mojo/Promise.pm
  4. +7 −0 t/mojo/promise.t
View
@@ -2,7 +2,11 @@
7.66 2018-02-13
- This release contains fixes for security issues, everybody should upgrade!
- Removed origin attribute of Mojo::Cookie::Response.
+ - Removed deprecated data and remaining methods from Mojo::IOLoop::Delay.
- Added host_only attribute to Mojo::Cookie::Response.
+ - Improved all method in Mojo::Promise to resolve with no results if no
+ promises have been passed.
+ - Fixed a bug in Mojo::UserAgent::CookieJar where old cookies could be leaked.
7.65 2018-02-11
- Added EXPERIMENTAL timing->begin, timing->elapsed, timing->rps and
View
@@ -4,32 +4,15 @@ use Mojo::Base 'Mojo::Promise';
# DEPRECATED!
use base 'Mojo::EventEmitter';
-use Mojo::Util 'deprecated';
-
sub begin {
my ($self, $offset, $len) = @_;
$self->{pending}++;
my $id = $self->{counter}++;
return sub { $self->_step($id, $offset // 1, $len, @_) };
}
-# DEPRECATED!
-sub data {
- deprecated 'Mojo::IOLoop::Delay::data is DEPRECATED';
- Mojo::Util::_stash(data => @_);
-}
-
sub pass { $_[0]->begin->(@_) }
-# DEPRECATED!
-sub remaining {
- deprecated 'Mojo::IOLoop::Delay::remaining is DEPRECATED';
- my $self = shift;
- return $self->{steps} ||= [] unless @_;
- $self->{steps} = shift;
- return $self;
-}
-
sub steps {
my ($self, @steps) = @_;
$self->{steps} = \@steps;
View
@@ -28,7 +28,7 @@ sub all {
);
}
- return $all;
+ return @promises ? $all : $all->resolve([]);
}
sub catch { shift->then(undef, shift) }
View
@@ -185,6 +185,13 @@ Mojo::IOLoop->one_tick;
is_deeply \@results, [], 'promises not resolved';
is_deeply \@errors, ['third'], 'promise rejected';
+# Empty all
+(@results, @errors) = ();
+Mojo::Promise->all()->then(sub { @results = @_ }, sub { @errors = @_ });
+Mojo::IOLoop->one_tick;
+is_deeply \@results, [[]], 'promise resolved';
+is_deeply \@errors, [], 'promise not rejected';
+
# Settle with promise
$promise = Mojo::Promise->new->resolve('works');
@results = ();

0 comments on commit a18da70

Please sign in to comment.