-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: optimistically create streams for light protocols #1514
Conversation
size-limit report 📦
|
ba290ec
to
c269e6d
Compare
|
||
export class StreamManager { | ||
private streamsPool: Map<string, Stream[]> = new Map(); | ||
private ongoingStreamCreations: Map<string, Promise<Stream>> = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it simpler by not having a "pool" of stream, but just one stream.
Also, once you created a stream, I'd just store the Promise<Stream>
and that's it. and just return this promise
} | ||
|
||
this.log(`No stream available for peer ${peerIdStr}. Opening a new one.`); | ||
return this.createAndSaveStream(peer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you dont need to "create and save", you just need to return a fresh new stream
const peerStreams = this.streamsPool.get(peerIdStr) || []; | ||
peerStreams.push(stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure this could be your race condition. Not 100% sure how it work with the JavaScript event loop.
Maybe @weboko can advise.
In any case, I would not have a array of stream, just have 1
closing in favour of #1516 |
!! not to be merged -- optimisations and testing to be done !!
Results:
Thoughts/TODOs:
StreamManager
to increase readability