Skip to content

Commit 8c98aa2

Browse files
committed
Improve message box config
1 parent 022ec34 commit 8c98aa2

File tree

5 files changed

+27
-104
lines changed

5 files changed

+27
-104
lines changed

src/Internal/Poller/SaucerPoller.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
use Boson\ApplicationId;
88
use Boson\Component\Saucer\SaucerInterface;
9-
use Boson\Poller\CancellableTask;
109
use Boson\Poller\PollerInterface;
1110
use Boson\Poller\Suspension;
12-
use Boson\Poller\TaskInterface;
1311
use Boson\Shared\IdValueGenerator\IdValueGeneratorInterface;
1412
use Boson\Shared\IdValueGenerator\PlatformDependentIntValueGenerator;
1513
use FFI\CData;
@@ -109,35 +107,35 @@ private function executeQueuedTask(): void
109107
}
110108
}
111109

112-
public function defer(callable $task): CancellableTask
110+
public function defer(callable $task): int|string
113111
{
114112
$this->queueTasks[$id = $this->ids->nextId()] = $task(...);
115113

116-
return new CancellableTask($this, $id);
114+
return $id;
117115
}
118116

119-
public function repeat(callable $task): CancellableTask
117+
public function repeat(callable $task): int|string
120118
{
121119
$this->periodicTasks[$id = $this->ids->nextId()] = $task(...);
122120

123-
return new CancellableTask($this, $id);
121+
return $id;
124122
}
125123

126-
public function delay(float $delay, callable $task): CancellableTask
124+
public function delay(float $delay, callable $task): int|string
127125
{
128126
$stopsAfter = \microtime(true) + $delay;
129127

130-
return $this->repeat(function (TaskInterface $id) use ($stopsAfter, $task): void {
128+
return $this->repeat(function (string|int $taskId) use ($stopsAfter, $task): void {
131129
if (\microtime(true) > $stopsAfter) {
132-
$task($id);
130+
$task($taskId);
133131

134-
$this->cancel($id);
132+
$this->cancel($taskId);
135133
}
136134
});
137135
}
138136

139-
public function cancel(TaskInterface $task): void
137+
public function cancel(int|string $taskId): void
140138
{
141-
unset($this->periodicTasks[$task->id], $this->queueTasks[$task->id]);
139+
unset($this->periodicTasks[$taskId], $this->queueTasks[$taskId]);
142140
}
143141
}

src/Poller/CancellableTask.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Poller/CancellableTaskInterface.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Poller/PollerInterface.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Boson\Poller;
66

77
/**
8-
* @template TTaskId of array-key = array-key
8+
* @phpstan-type TaskIdType array-key
99
*/
1010
interface 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
}

src/Poller/TaskInterface.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)