From 77f78d9bc33cacd28bdd30482403da48895b19c5 Mon Sep 17 00:00:00 2001 From: Jan Sorgalla Date: Sun, 5 Oct 2014 19:42:19 +0200 Subject: [PATCH] Avoid unnecessary creation of closures when no canceller is given --- src/Promise.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Promise.php b/src/Promise.php index ead3106e..aa8d914e 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -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) {