55namespace Boson \Poller ;
66
77/**
8- * @template TTaskId of array-key = array-key
8+ * @phpstan-type TaskIdType array-key
99 */
1010interface PollerInterface
1111{
@@ -23,39 +23,43 @@ public function createSuspension(): SuspensionInterface;
2323 /**
2424 * Defer the execution of a callback.
2525 *
26- * @param callable(TaskInterface<TTaskId> ):void $task the callback to defer
26+ * @param callable(TaskIdType ):void $task the callback to defer
2727 *
28- * @return TaskInterface<TTaskId>
28+ * @return TaskIdType a unique identifier that can be used to cancel
29+ * the callback
2930 */
30- public function defer (callable $ task ): TaskInterface ;
31+ public function defer (callable $ task ): int | string ;
3132
3233 /**
3334 * Repeatedly execute a callback.
3435 *
35- * @param callable(TaskInterface<TTaskId> ):void $task the callback to execute
36+ * @param callable(TaskIdType ):void $task the callback to execute
3637 *
37- * @return TaskInterface<TTaskId>
38+ * @return TaskIdType a unique identifier that can be used to cancel
39+ * the callback
3840 */
39- public function repeat (callable $ task ): TaskInterface ;
41+ public function repeat (callable $ task ): int | string ;
4042
4143 /**
4244 * Delay the execution of a callback.
4345 *
4446 * @param float $delay the amount of time, in seconds, to delay the execution for
45- * @param callable(TaskInterface<TTaskId> ):void $task the callback to delay
47+ * @param callable(TaskIdType ):void $task the callback to delay
4648 *
47- * @return TaskInterface<TTaskId>
49+ * @return TaskIdType a unique identifier that can be used to
50+ * cancel the callback
4851 */
49- public function delay (float $ delay , callable $ task ): TaskInterface ;
52+ public function delay (float $ delay , callable $ task ): int | string ;
5053
5154 /**
5255 * Cancel a task.
5356 *
5457 * This will detach the event loop from all resources that are associated
5558 * to the callback. After this operation the callback is permanently
56- * invalid.
59+ * invalid. Calling this function MUST NOT fail, even if passed an invalid
60+ * identifier.
5761 *
58- * @param TaskInterface<TTaskId> $task
62+ * @param TaskIdType $taskId the callback identifier
5963 */
60- public function cancel (TaskInterface $ task ): void ;
64+ public function cancel (int | string $ taskId ): void ;
6165}
0 commit comments