padenot / ringbuf.js

Wait-free thread-safe single-consumer single-producer ring buffer using SharedArrayBuffer
https://ringbuf-js.netlify.app/
Mozilla Public License 2.0
201 stars 18 forks source link

End of Stream Signal #4

Closed anthumchris closed 4 years ago

anthumchris commented 4 years ago

Would it be helpful for RingBuffer to store an internal "end of stream" signal received by the producer to notify the consumer? Or should that be managed externally? For example, a cross-realm scenario could avoid async messaging by setting/getting the end flags:

// main.js
[ numWritten, didAllWrite ] = ringBuffer.write(elements, isEnd)

// worker.js
[ numRead, isEnd ] = ringBuffer.read(elements)
padenot commented 4 years ago

This is high level for this ring buffer. You want to either have a packet system where you can have arbitrary messages (like the parameter change examples), or have sentinel values in the audio stream that signal EOS.