ts-stream icon indicating copy to clipboard operation
ts-stream copied to clipboard

How to implement such case ?

Open MarcWeber opened this issue 3 years ago • 1 comments

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.

MarcWeber avatar Feb 09 '21 20:02 MarcWeber

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?

poelstra avatar Feb 10 '21 22:02 poelstra