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

How to implement such case ? #56

Open
MarcWeber opened this issue Feb 9, 2021 · 1 comment
Open

How to implement such case ? #56

MarcWeber opened this issue Feb 9, 2021 · 1 comment

Comments

@MarcWeber
Copy link

MarcWeber commented Feb 9, 2021

const list =  range(1,100)
const stream = new Stream()
const add_to_stream = async () => {
  stream.write(something)
  stream.end() // would end for all other users
}
Promise.all(list.map( x => add_to_stream()))

The most simple way would be having end() only end the stream if a new refcounting per stream would turn 0.

Then code would look like

stream.addRefCounter(list.length)
Promise.all() ...

And it would just do what it should. Am I missing something ?
Thus default refcount should be 1.

I am unsure what should be done about error and endedResult. Allow a list to be built up internally?
What should result() be returning then ? A list ? Would break code. Add resultMany() returning all ?
I don't use result in my use case.

@poelstra
Copy link
Owner

Hi Marc, thanks for chiming in!

I'm not entirely sure what you're trying to achieve exactly, your example seems a bit too contrived for me to grasp.
Can you clarify?

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