buffer method

ReadableBufferedBeacon<T> buffer(
  1. int count, {
  2. String? name,
})

Returns a BufferedCountBeacon that wraps this Beacon.

final count = Beacon.writable(10);
final bufferedBeacon = count.buffer(2);
BeaconScheduler.flush(); // allow buffer to read first value

expect(bufferedBeacon.value, equals([]));
expect(bufferedBeacon.currentBuffer.value, equals([10]));

count.set(20);
BeaconScheduler.flush();

expect(bufferedBeacon.value, equals([10, 20]));
expect(bufferedBeacon.currentBuffer.value, equals([]));

See: Beacon.bufferedCount for more details.

Implementation

ReadableBufferedBeacon<T> buffer(
  int count, {
  String? name,
}) {
  assert(
    this is! BufferedBaseBeacon,
    '''
Chaining of buffered beacons is not supported!
Buffered beacons has to be the last in the chain.

Good: someBeacon.filter().buffer(10);

Bad: someBeacon.buffer(10).filter();

If you absolutely need this functionality, it has to be done manually with "wrap".
eg:
final beacon = Beacon.bufferedCount<T>(count).wrap(someBufferedBeacon)
''',
  );

  final beacon = Beacon.bufferedCount<T>(
    count,
    name: name,
  );

  _wrapThis(beacon);

  return beacon;
}