Skip to content

Commit 893777b

Browse files
committed
Cancellation handler must only be called once
1 parent ac376a5 commit 893777b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/React/Promise/Deferred.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,14 @@ public function cancel()
128128
return;
129129
}
130130

131+
$canceller = $this->canceller;
132+
$this->canceller = null;
133+
131134
try {
132135
$that = $this;
133136

134137
call_user_func(
135-
$this->canceller,
138+
$canceller,
136139
function ($value = null) use ($that) {
137140
$that->resolve($value);
138141
},

tests/React/Promise/DeferredTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public function shouldInvokeCancellationHandlerAndStayPendingWhenCallingCancel()
114114
$d->then($this->expectCallableNever(), $this->expectCallableNever());
115115
}
116116

117+
/** @test */
118+
public function shouldInvokeCancellationHandlerOnlyOnceWhenCallingCancelMultipleTimes()
119+
{
120+
$d = new Deferred($this->expectCallableOnce());
121+
$d->cancel();
122+
$d->cancel();
123+
}
124+
117125
/** @test */
118126
public function shouldResolveWhenCancellationHandlerResolves()
119127
{

0 commit comments

Comments
 (0)