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

Do we want a channel-based parallel processor? #56

Closed
sudhirj opened this issue Jan 12, 2023 · 2 comments
Closed

Do we want a channel-based parallel processor? #56

sudhirj opened this issue Jan 12, 2023 · 2 comments

Comments

@sudhirj
Copy link

sudhirj commented Jan 12, 2023

I've written https://github.com/sudhirj/cirque

It basically takes a processing function and gives you an input and output channel, and inputs sent to the input channel and processed in parallel with the results sent in order on the output channel. Very similar to Stream but off a channel API.

If we want to roll this into conc and based it off Stream I can raise a PR.

@camdencheek
Copy link
Member

I generally shy away from using channels in a public API because they're easy to misuse. In the case of conc, I think it would be difficult to provide a channel-based API that can still maintain the same guarantees about scoping and cleanup.

Let's take the API of cirque as an example, where both an input and an output channel is returned:

  • How do we propagate panics? The only way we know the stream has completed is by waiting for a closed signal on the output channel.
  • How do we avoid requiring the user to spawn a separate goroutine to write to the input channel?
  • How do we guarantee that the input channel will always be closed? If the calling thread panics, if the user didn't defer close(input), the goroutines in the stream will block forever, leaking goroutines.
  • What if the caller returns early without consuming all messages from the output channel? Will the spawned goroutines block forever?

I'd like to keep the API of conc as hard to misuse as possible, and channels make that difficult. That said, even if difficult, it might not be impossible, so I'm willing to entertain proposals 🙂

@sudhirj
Copy link
Author

sudhirj commented Jan 13, 2023

That sounds reasonable, yeah, I don't think a channel API fits those constraints.

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