spatie / async

Easily run code asynchronously

Home Page:https://spatie.be/en/opensource/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing Data within "timeout" Callback

futureweb opened this issue · comments

use Spatie\Async\Pool;

$pool = Pool::create();

foreach ($things as $thing) {
    $pool->add(function () use ($thing) {
        // Do a thing
    })->then(function ($output) {
        // Handle success
    })->timeout(function () {
        echo $thing;
    });
}

$pool->wait();

In the above example one will get an Error that "$thing" isn't defined in timeout Callback ... is there any way to access the Data from $thing within the timeout Callback?
As I would need to do some DB Actions on timeout ...

Thank you
Andy

timeout(function() use($thing) { // your stuff })

so obvious ... must have been massively overtired ... 🙄🤦🏻‍♂️
thx ;-)