Skip to content

Commit ffda869

Browse files
committed
Better cancelled execution creation
1 parent a00eb2d commit ffda869

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Worker/Internal/ContextWorker.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ public function submit(Task $task, ?Cancellation $cancellation = null): Executio
142142
throw new StatusError("The worker has been shut down");
143143
}
144144

145-
if ($cancellation?->isRequested()) {
146-
return self::createCancelledExecution($task, $cancellation);
145+
try {
146+
$cancellation?->throwIfRequested();
147+
} catch (CancelledException $exception) {
148+
return self::createCancelledExecution($task, $exception);
147149
}
148150

149151
$receive = empty($this->jobQueue);
@@ -229,16 +231,11 @@ public function kill(): void
229231
$this->exitStatus->ignore();
230232
}
231233

232-
private static function createCancelledExecution(Task $task, Cancellation $cancellation): Execution
234+
private static function createCancelledExecution(Task $task, CancelledException $exception): Execution
233235
{
234236
$channel = new StreamChannel(new ReadableBuffer(), new WritableBuffer());
235237
$channel->close();
236238

237-
try {
238-
$cancellation->throwIfRequested();
239-
throw new \Error('Expected cancellation to have been requested');
240-
} catch (CancelledException $exception) {
241-
return new Execution($task, $channel, Future::error($exception));
242-
}
239+
return new Execution($task, $channel, Future::error($exception));
243240
}
244241
}

0 commit comments

Comments
 (0)