A SharedArrayBuffer obtained by calling RingBuffer.getStorageForCapacity.
A typed array constructor, the type that this ring buffer will hold.
Read up to elements.length
elements from the ring buffer. elements
is a typed
array of the same type as passed in the ctor.
Returns the number of elements read from the queue, they are placed at the
beginning of the array passed as parameter.
An array in which the elements read from the queue will be written, starting at the beginning of the array.
Optional
length: numberIf passed, the maximum number of elements to pop. If not passed, up to elements.length are popped.
If passed, an index in elements in which the data is
written to. elements.length - offset
must be greater or equal to
length
.
The number of elements read from the queue.
Push elements to the ring buffer.
A typed array of the same type as passed in the ctor, to be written to the queue.
Optional
length: numberIf passed, the maximum number of elements to push. If not passed, all elements in the input array are pushed.
If passed, a starting index in elements from which the elements are read. If not passed, elements are read from index 0.
the number of elements written to the queue.
Write bytes to the ring buffer using callbacks. This create wrapper
objects and can GC, so it's best to no use this variant from a real-time
thread such as an AudioWorklerProcessor process
method.
The callback is passed two typed arrays of the same type, to be filled.
This allows skipping copies if the API that produces the data writes is
passed arrays to write to, such as AudioData.copyTo
.
The maximum number of elements to write to the ring buffer. If amount is more than the number of slots available for writing, then the number of slots available for writing will be made available: no overwriting of elements can happen.
A callback with two parameters, that are two typed array of the correct type, in which the data need to be copied. If the callback doesn't return anything, it is assumed all the elements have been written to. Otherwise, it is assumed that the returned number is the number of elements that have been written to, and those elements have been written started at the beginning of the requested buffer space.
The number of elements written to the queue.
Write bytes to the ring buffer using a callback.
This allows skipping copies if the API that produces the data writes is
passed arrays to write to, such as AudioData.copyTo
.
The maximum number of elements to write to the ring buffer. If amount is more than the number of slots available for writing, then the number of slots available for writing will be made available: no overwriting of elements can happen.
A callback with five parameters:
(1) The internal storage of the ring buffer as a typed array (2) An offset to start writing from (3) A number of elements to write at this offset (4) Another offset to start writing from (5) A number of elements to write at this second offset
If the callback doesn't return anything, it is assumed all the elements have been written to. Otherwise, it is assumed that the returned number is the number of elements that have been written to, and those elements have been written started at the beginning of the requested buffer space.
The number of elements written to the queue.
Static
getAllocate the SharedArrayBuffer for a RingBuffer, based on the type and capacity required
The number of elements the ring buffer will be able to hold.
A typed array constructor, the type that this ring buffer will hold.
A SharedArrayBuffer of the right size.
The base RingBuffer class
A Single Producer - Single Consumer thread-safe wait-free ring buffer.
The producer and the consumer can be on separate threads, but cannot change roles, except with external synchronization.