You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReadableStreamMessageReader.listen should register data handler once per readeable #1568
The issue is that if the listen() is called multiple times. The callback gets overwritten but , we now have two onData events registered.
The proposal to change is this, so that onData is registered on the reader when the instance is created, and not on listen. Also, the dispose removes callback, and not the onData handler.
For efficiency, we don't need to process data unless there is a listener on. So, adding a isEmpty to the Emitter, and using emitter to manage callbacks and cleanup.
I don’t want to call listen multiple times. My worry is since we allowed it. Throwing now may cause crashes. If that is not a risk then, exception option is better.
I do want to suggest that, if the reader is only going to be bound to one readable, then all the events should be hooked up in the constructor. The only thing that the listen needs to do is this:
publiclisten(callback: DataCallback): Disposable{if(this.callback!==undefined){thrownewError('Reader can only listen once.');}this.callback=callback;returnnewDisposable(()=>({this.callback =undefined}));}
Activity
dbaeumer commentedon Oct 11, 2024
I actually prefer to not allowing this and throw like coded here: dbaeumer/probable-muskox-peach
Can you explain why you want to call listen n times.
karthiknadig commentedon Oct 11, 2024
I don’t want to call listen multiple times. My worry is since we allowed it. Throwing now may cause crashes. If that is not a risk then, exception option is better.
karthiknadig commentedon Oct 11, 2024
If there is no concern with potentially crashing consumers of that API, then I like direction this implementation is going:
vscode-languageserver-node/jsonrpc/src/common/messageReader.ts
Lines 202 to 217 in a5a067b
I do want to suggest that, if the reader is only going to be bound to one readable, then all the events should be hooked up in the constructor. The only thing that the listen needs to do is this:
the constructor should be doing this:
dbaeumer commentedon Oct 14, 2024
I agree with the approach of hooking things up in the constructor since we pass in the readable there.