MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
https://matthewwid.github.io/better-sse/
MIT License
537 stars 14 forks source link

Serialize write buffer on dispatch instead of each data write call. #1

Closed MatthewWid closed 3 years ago

MatthewWid commented 3 years ago

Instead of serializing and JSON-ifying each and every data write, buffer all calls to the Session#data method into a large data buffer and then serialize that buffer once upon Session#dispatching.

This makes it so deserializing the data on the client-side works properly when there is more than one call to the Session#data method in-between event dispatches.

MatthewWid commented 3 years ago

Resolved by instead leaving it to the client to deserialize JSON on each newline when multiple data items are given in a single event, instead of trying to somehow concatenate buffered data on the server-end to a serializable value to send as a single data item.