Skip to content

Commit 791d6f4

Browse files
committed
Try using new closure library
1 parent 9d8aa92 commit 791d6f4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/AsyncTask.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
use Closure;
88
use Illuminate\Process\InvokedProcess;
99
use Illuminate\Support\Facades\Process;
10-
use Laravel\SerializableClosure\SerializableClosure;
1110
use LogicException;
1211
use loophp\phposinfo\OsInfo;
1312
use RuntimeException;
1413

14+
use function Opis\Closure\{serialize, unserialize};
15+
1516
/**
1617
* The common handler of an AsyncTask; this can be a closure (will be wrapped inside AsyncTask) or an interface instance.
1718
*/
1819
class AsyncTask
1920
{
2021
/**
2122
* The task to be executed in the background.
22-
* @var SerializableClosure|AsyncTaskInterface
23+
* @var Closure|AsyncTaskInterface
2324
*/
24-
private SerializableClosure|AsyncTaskInterface $theTask;
25+
private Closure|AsyncTaskInterface $theTask;
2526

2627
/**
2728
* The process that is actually running this task. Tasks that are not started will have null here.
@@ -94,10 +95,7 @@ class AsyncTask
9495
*/
9596
public function __construct(Closure|AsyncTaskInterface $theTask)
9697
{
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
10199
$this->theTask = $theTask;
102100
}
103101

@@ -142,10 +140,8 @@ public function run(): void
142140
}
143141

144142
// 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)();
149145
} else {
150146
// must be AsyncTaskInterface
151147
$this->theTask->execute();

0 commit comments

Comments
 (0)