pub struct SampleQueue { /* private fields */ }Expand description
A queue that never blocks its writer.
Implementations§
Source§impl SampleQueue
impl SampleQueue
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Build a queue that holds capacity samples.
A capacity of zero would drop every sample, so the value floors at 1.
liblsl floors the same way (src/stream_info_impl.cpp:268).
Sourcepub fn dropped(&self) -> u64
pub fn dropped(&self) -> u64
How many samples the queue has dropped.
Nothing on the wire carries this number. SPEC.md 8.7 records that a reader cannot see a loss, so this exists for a local report only.
Sourcepub fn push(&self, s: Sample)
pub fn push(&self, s: Sample)
Add one sample. This never waits.
A full queue loses its oldest sample. The writer carries on, so a slow reader never holds back the source. SPEC.md 8.7.
Sourcepub fn push_many(&self, samples: &[Sample])
pub fn push_many(&self, samples: &[Sample])
Add several samples with one lock. This never waits.
The result is the same as one SampleQueue::push for each sample, in
order. A full queue loses its oldest samples, and the count of dropped
samples grows by the number that the queue lost. The recorded behavior in
artifacts/behavior-liblsl.json therefore still holds.
One lock for a block is the difference between a stream that a program can read at 1000 Hz and one that it cannot.
Sourcepub fn pop(&self, timeout: Duration) -> Option<Sample>
pub fn pop(&self, timeout: Duration) -> Option<Sample>
Take the oldest sample, waiting up to timeout.
Returns None when the timeout passes with nothing waiting, or when the
queue is closed and empty.
Sourcepub fn pop_many(
&self,
out: &mut Vec<Sample>,
max: usize,
timeout: Duration,
) -> usize
pub fn pop_many( &self, out: &mut Vec<Sample>, max: usize, timeout: Duration, ) -> usize
Take every sample that waits, up to max, with one lock.
The samples go to the end of out. The call gives how many it added.
The timeout applies to the first sample only. When one sample waits, the
call takes what is there and returns. It never waits for max samples,
because a program that shows live signals must show what arrived.
A closed and empty queue gives zero.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
True once SampleQueue::close has run.