|
7 | 7 | use Closure; |
8 | 8 | use Illuminate\Process\InvokedProcess; |
9 | 9 | use Illuminate\Support\Facades\Process; |
10 | | -use Laravel\SerializableClosure\SerializableClosure; |
11 | 10 | use LogicException; |
12 | 11 | use loophp\phposinfo\OsInfo; |
13 | 12 | use RuntimeException; |
14 | 13 |
|
| 14 | +use function Opis\Closure\{serialize, unserialize}; |
| 15 | + |
15 | 16 | /** |
16 | 17 | * The common handler of an AsyncTask; this can be a closure (will be wrapped inside AsyncTask) or an interface instance. |
17 | 18 | */ |
18 | 19 | class AsyncTask |
19 | 20 | { |
20 | 21 | /** |
21 | 22 | * The task to be executed in the background. |
22 | | - * @var SerializableClosure|AsyncTaskInterface |
| 23 | + * @var Closure|AsyncTaskInterface |
23 | 24 | */ |
24 | | - private SerializableClosure|AsyncTaskInterface $theTask; |
| 25 | + private Closure|AsyncTaskInterface $theTask; |
25 | 26 |
|
26 | 27 | /** |
27 | 28 | * The process that is actually running this task. Tasks that are not started will have null here. |
@@ -94,10 +95,7 @@ class AsyncTask |
94 | 95 | */ |
95 | 96 | public function __construct(Closure|AsyncTaskInterface $theTask) |
96 | 97 | { |
97 | | - if ($theTask instanceof Closure) { |
98 | | - // convert to serializable closure first |
99 | | - $theTask = new SerializableClosure($theTask); |
100 | | - } |
| 98 | + // opis/closure allows direct storage of closure |
101 | 99 | $this->theTask = $theTask; |
102 | 100 | } |
103 | 101 |
|
@@ -142,10 +140,8 @@ public function run(): void |
142 | 140 | } |
143 | 141 |
|
144 | 142 | // then, execute the task itself |
145 | | - if ($this->theTask instanceof SerializableClosure) { |
146 | | - $innerClosure = $this->theTask->getClosure(); |
147 | | - $innerClosure(); |
148 | | - unset($innerClosure); |
| 143 | + if ($this->theTask instanceof Closure) { |
| 144 | + ($this->theTask)(); |
149 | 145 | } else { |
150 | 146 | // must be AsyncTaskInterface |
151 | 147 | $this->theTask->execute(); |
|
0 commit comments