binaryminds / react-native-sse

Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
https://www.npmjs.com/package/react-native-sse
MIT License
174 stars 27 forks source link

What is the purpose of `timeoutBeforeConnection`? #32

Closed dobomode closed 4 months ago

dobomode commented 7 months ago

Currently timeoutBeforeConnection defaults to 500ms and introduces an artificial latency in my app's requests. Is there any specific reason this is the case and why wouldn't we always prefer to set this to 0ms (no latency)?

EmilJunker commented 7 months ago

I'm not sure, but I would say this timeout is there to give you enough time to register the event listeners. Imagine an error happens immediately when you try to open the SSE connection but you haven't added your event listeners yet, so you can't handle the error. However, for this purpose a timeout of 50ms or so would probably be enough 🤔

wojciechkrol commented 4 months ago

@dobomode When you create an EventSource instance it starts connection. timeoutBeforeConnection gives time to initialize all event listeners.