Skip to content

Commit

Permalink
Avoid unnecessary creation of closures when no canceller is given
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Oct 5, 2014
1 parent d5b6f8e commit 77f78d9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function then(callable $onFulfilled = null, callable $onRejected = null,
return $this->result->then($onFulfilled, $onRejected, $onProgress);
}

if (null === $this->canceller) {
return new static($this->resolver($onFulfilled, $onRejected, $onProgress));
}

$this->requiredCancelRequests++;

return new static($this->resolver($onFulfilled, $onRejected, $onProgress), function ($resolve, $reject, $progress) {
Expand Down

1 comment on commit 77f78d9

@mtdowling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Please sign in to comment.