Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ public function cancel()
return;
}

$this->call($this->canceller);
$canceller = $this->canceller;
$this->canceller = null;

$this->call($canceller);
}

private function resolver(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
Expand Down
25 changes: 25 additions & 0 deletions tests/PromiseTest/CancelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,31 @@ public function cancelShouldTriggerCancellerWhenAllChildrenCancel()
$child2->cancel();
}

/** @test */
public function cancelShouldNotTriggerCancellerWhenCancellingOneChildrenMultipleTimes()
{
$adapter = $this->getPromiseTestAdapter($this->expectCallableNever());

$child1 = $adapter->promise()
->then()
->then();

$child2 = $adapter->promise()
->then();

$child1->cancel();
$child1->cancel();
}

/** @test */
public function cancelShouldTriggerCancellerOnlyOnceWhenCancellingMultipleTimes()
{
$adapter = $this->getPromiseTestAdapter($this->expectCallableOnce());

$adapter->promise()->cancel();
$adapter->promise()->cancel();
}

/** @test */
public function cancelShouldAlwaysTriggerCancellerWhenCalledOnRootPromise()
{
Expand Down