You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an array of items of variable length where I want to process each item by the same function after the previous promise has resolved. I just can't figure out how to code it, I keep ending up thinking in loops while I guess I shouldn't:
$items = array(...variable number of items in here...);
$this->doSomethingAsyncAndReturnAPromise($firstItem)->then(
function () {
$this->doSomethingAsyncAndReturnAPromise($secondItem)->then(
... and so on for all the remaining $items
);
}
);
Can anyone point me in the right direction how to do this?
The text was updated successfully, but these errors were encountered:
They both work exactly like PHP's array_map and array_reduce with the addition that the values of the input array can be promises and the callbacks can return promises.
In this case, we're "abusing" reduce() for your use case. Since the callback must receive the return value of the previous iteration, reduce() takes care of running in sequence.
I have an array of items of variable length where I want to process each item by the same function after the previous promise has resolved. I just can't figure out how to code it, I keep ending up thinking in loops while I guess I shouldn't:
Can anyone point me in the right direction how to do this?
The text was updated successfully, but these errors were encountered: