55namespace Boson \Poller ;
66
77/**
8- * @phpstan-type TaskIdType array-key
8+ * @template TTaskId of array-key = array-key
99 */
1010interface PollerInterface
1111{
@@ -23,43 +23,39 @@ public function createSuspension(): SuspensionInterface;
2323 /**
2424 * Defer the execution of a callback.
2525 *
26- * @param callable(TaskIdType ):void $task the callback to defer
26+ * @param callable(TaskInterface<TTaskId> ):void $task the callback to defer
2727 *
28- * @return TaskIdType a unique identifier that can be used to cancel
29- * the callback
28+ * @return TaskInterface<TTaskId>
3029 */
31- public function defer (callable $ task ): int | string ;
30+ public function defer (callable $ task ): TaskInterface ;
3231
3332 /**
3433 * Repeatedly execute a callback.
3534 *
36- * @param callable(TaskIdType ):void $task the callback to execute
35+ * @param callable(TaskInterface<TTaskId> ):void $task the callback to execute
3736 *
38- * @return TaskIdType a unique identifier that can be used to cancel
39- * the callback
37+ * @return TaskInterface<TTaskId>
4038 */
41- public function repeat (callable $ task ): int | string ;
39+ public function repeat (callable $ task ): TaskInterface ;
4240
4341 /**
4442 * Delay the execution of a callback.
4543 *
4644 * @param float $delay the amount of time, in seconds, to delay the execution for
47- * @param callable(TaskIdType ):void $task the callback to delay
45+ * @param callable(TaskInterface<TTaskId> ):void $task the callback to delay
4846 *
49- * @return TaskIdType a unique identifier that can be used to
50- * cancel the callback
47+ * @return TaskInterface<TTaskId>
5148 */
52- public function delay (float $ delay , callable $ task ): int | string ;
49+ public function delay (float $ delay , callable $ task ): TaskInterface ;
5350
5451 /**
5552 * Cancel a task.
5653 *
5754 * This will detach the event loop from all resources that are associated
5855 * to the callback. After this operation the callback is permanently
59- * invalid. Calling this function MUST NOT fail, even if passed an invalid
60- * identifier.
56+ * invalid.
6157 *
62- * @param TaskIdType $taskId the callback identifier
58+ * @param TaskInterface<TTaskId> $task
6359 */
64- public function cancel (int | string $ taskId ): void ;
60+ public function cancel (TaskInterface $ task ): void ;
6561}
0 commit comments