promises icon indicating copy to clipboard operation
promises copied to clipboard

Add $config to the signatures of Utils::all and Each::of ?

Open jwadhams opened this issue 2 years ago • 0 comments

Description Does it make sense to add $config as a third optional parameter to Utils::all, so that callers have more control over the underlying EachPromise (like concurrency)?

Example Current code: (this is based on my understanding of Utils::all, unrolled so I can pass $config to EachPromise. If I'm doing this the hard way, this whole request could be moot)

$everything = [];
return (new EachPromise($requestPromises, [
    'concurrency' => 5,
    'fulfilled' => function ($oneResult) use (&$everything) {
        $everything = array_merge($everything, $oneResult);
    },
]))
    ->promise()
    ->then(function () use (&$everything) {
         return $everything;
    });

Desired code:

return Utils::all($requestPromises, false, ['concurrency' => 5])->then(function ($results)  {
    return array_merge(...$results);
});

Additional context I'd be happy to submit a PR for this, I mostly wanted some advice if this is even a good idea, in line with how you want the library to work.

jwadhams avatar Nov 23 '21 00:11 jwadhams