I am testing spatie's async project. I created a task as such.
use Spatie\Async\Task;
class ServiceTask extends Task
{
protected $accountService;
protected $serviceFactory;
public function __construct(ServiceFactory $serviceFactory)
{
$this->serviceFactory = $serviceFactory;
}
public function configure()
{
$this->accountService = $this->serviceFactory->getAccountService();
}
public function run()
{
//accounting tasks
}
}
And for the pool:
$pool = Pool::create();
foreach ($transactions as $transaction) {
$pool->add(new ServiceTask($serviceFactory))
// handlers
;
}
$pool->wait();
When I run the above code, I simply get
Serialization of 'Closure' is not allowed
I know that we cannot simply serialize a closure, I tried the same code above with a simple plain Data Transfer Object, it worked fine. But when passing a service, or a container class from symfony I get above error. Is there a work around for this?