Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map output of concurrecy calls to the index of the input #53135

Merged
merged 8 commits into from
Oct 16, 2024

Conversation

ovp87
Copy link
Contributor

@ovp87 ovp87 commented Oct 12, 2024

Changes the output of the concurrency calls in the Process and Fork drivers, to respect the index on the input.
This was already being done when using the sync driver, this brings the output of the other drivers into sync.

Meaning that this is now possible regardless of driver:

$result = Concurrency::run([
    'task1' => function () {
        return 'Result of task 1';
    },
    'task2' => function () {
        return 'Result of task 2';
    },
]);

With an output that matches the index of the input, essentially allowing you to index the output from each of the calls:

['task1' => 'Result of task 1', 'task2' => 'Result of task 2']

I found this useful when dealing with a dynamic number of closures, where to use previous mapping solutions
[$first, $second] = Concurrency::run(...) was tricky.

ovp87 added 2 commits October 13, 2024 01:45
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
@taylorotwell
Copy link
Member

taylorotwell commented Oct 14, 2024

Hey there @ovp87 - could you take a stab at just updating the Fork driver and I'll give it a test on my end? Please mark as ready for review when the requested changes have been made.

@taylorotwell taylorotwell marked this pull request as draft October 14, 2024 13:03
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
@ovp87 ovp87 marked this pull request as ready for review October 15, 2024 22:14
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
@ovp87
Copy link
Contributor Author

ovp87 commented Oct 15, 2024

@taylorotwell I've modified the Fork driver, and tested it, looks like it works fine.

I've commented out the test tough, since the package is not there by default, and i'm not sure if i should be adding it to the dev dependencies just for the test.

ovp87 and others added 4 commits October 16, 2024 00:24
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
Signed-off-by: Ola Valø Pettersen <ola@24nettbutikk.no>
@taylorotwell taylorotwell merged commit 42c1c84 into laravel:master Oct 16, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants