MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
MIT License
485 stars 14 forks source link

Session event batching #54

Closed MatthewWid closed 11 months ago

MatthewWid commented 11 months ago

Resolves #42.

This PR adds the ability to batch and send multiple events at once to a session using event buffers.


Example usage:

session.batch((batched) => {
  for (let i = 0; i < 100; ++i) {
    batched.push(`Event no. ${i}`);
  }
});

Using the exact same helpers as you would with Session (push, iterate and stream) you can batch together many events and then send all them in a single transmission.

This is more significantly more performant and uses less network bandwidth overall, and is a necessary precursor to implementing the event history API.

See the API documentation for more.