spatie / async

Easily run code asynchronously
https://spatie.be/en/opensource/php
MIT License
2.65k stars 179 forks source link

how to get the $output from Task #228

Open handhikadj opened 3 months ago

handhikadj commented 3 months ago

in Laravel, I created a Task but it seems I can't get the returned data from the run method inside a Task class. the $output returns false

class MyTask extends Task
{
   public function configure() {}

   public function run() {
     return 'a'; // just an example. I can't get this data on the then()'s $output
   }
}

$pool = Pool::create()->autoload(public_path('index.php'));

foreach ($items as $item) {
  $pool->add(new MyTask())
  ->then(function ($output) {
    echo $output;
  })
}