Skip to content

Commit

Permalink
Merge pull request #28 from sudevva/hotfix/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak by unset cancellers
  • Loading branch information
mcg-web authored Jun 15, 2018
2 parents 5aad49e + 2bb35bb commit 9a3be90
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function await($promise = null, $unwrap = false)
if (null === $promise) {
Deferred::runQueue();
SyncPromise::runQueue();
$this->cancellers = [];
return null;
}
$promiseAdapter = $this->getWebonyxPromiseAdapter();
Expand All @@ -133,6 +134,8 @@ public function await($promise = null, $unwrap = false)
throw $exception;
}

$hash = spl_object_hash($promise);
unset($this->cancellers[$hash]);
return $resolvedValue;
}

Expand All @@ -146,6 +149,7 @@ public function cancel($promise)
throw new \InvalidArgumentException(sprintf('The "%s" method must be called with a compatible Promise.', __METHOD__));
}
$canceller = $this->cancellers[$hash];
unset($this->cancellers[$hash]);
$adoptedPromise = $promise;
if ($promise instanceof Promise) {
$adoptedPromise = $promise->adoptedPromise;
Expand Down

0 comments on commit 9a3be90

Please sign in to comment.