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

Lambda producer should be run in the main thread #296

Open
kapcod opened this issue Jun 9, 2021 · 1 comment
Open

Lambda producer should be run in the main thread #296

kapcod opened this issue Jun 9, 2021 · 1 comment

Comments

@kapcod
Copy link

kapcod commented Jun 9, 2021

Currently, if the lambda provided instead of the queue/array/enumerable it's executed in one of the threads.
As far as I can see, the only reason to provide the producing lambda separately from the processing block is to separate the producer to run in the main thread.
Example (from real life, but simplified):
suppose user.generate_update takes 0.1s and MUST happen in the main thread due to DB connections limit
But send_update_api(params) takes 1s and so I want to parallelize the net calls in this case, so my idea for the code would be:

Parallel.each( -> { user = users.shift; user&.generate_update || Parallel::Stop }, in_threads: 10) do |params|
  send_update_api(params)
end

But the generate_update also runs in the threads and so I need to use another implementation, such as FixedThreadPool, or write my own solution.

@grosser
Copy link
Owner

grosser commented Jun 10, 2021 via email

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

No branches or pull requests

2 participants