chunkStream method

Stream<LSLTimedChunk> chunkStream({
  1. double wakeInterval = 0.1,
  2. int maxSamples = 1024,
  3. double coalesce = 0,
  4. int? maxBacklog,
  5. int? backlogWarnAt,
  6. void onBacklog(
    1. LSLBacklog backlog
    )?,
  7. int? debugFailAfter,
})

Samples as they arrive, in chunks, without polling.

As sampleStream, with the same isolate, rules and way of ending, but every time the isolate is woken it hands over all that is waiting as one LSLTimedChunk of at most maxSamples samples, as flat typed data (or strings). One message per wake rather than one per sample is what makes this usable for fast, wide streams.

A sender that does not chunk wakes the isolate once per sample. With coalesce (seconds) above zero the isolate goes on collecting for that long after the first sample, which bounds how often it delivers at the cost of that much latency. LSLTimedChunk.receivedClock is the arrival of the first sample either way, and LSLTimedChunk.readyCount says how many of the chunk's samples were there by then.

maxBacklog, backlogWarnAt and onBacklog are as for sampleStream and count samples, not chunks.

final subscription = inlet.chunkStream(coalesce: 0.005).listen((chunk) {
  final values = chunk.data as Float32List;
});
// ...
await subscription.cancel();
await inlet.destroy();

Implementation

Stream<LSLTimedChunk> chunkStream({
  double wakeInterval = 0.1,
  int maxSamples = 1024,
  double coalesce = 0,
  int? maxBacklog,
  int? backlogWarnAt,
  void Function(LSLBacklog backlog)? onBacklog,
  int? debugFailAfter,
}) => listenToInletChunks(
  inletAddress: _listenAddress,
  streamInfoAddress: streamInfo.streamInfo.address,
  wakeInterval: wakeInterval,
  maxSamples: maxSamples,
  coalesce: coalesce,
  maxBacklog: maxBacklog,
  backlogWarnAt: backlogWarnAt ?? _defaultBacklogWarnAt,
  onBacklog: onBacklog,
  onStarted: _listeners.add,
  onEnded: _listeners.remove,
  debugFailAfter: debugFailAfter,
);