buffer method

BufferedCountBeacon<T> buffer(
  1. int count, {
  2. String? name,
  3. bool synchronous = true,
})

Returns a BufferedCountBeacon that wraps this Beacon.

NB: All writes to the buffered beacon will be delegated to the wrapped beacon.

final count = Beacon.writable(10);
final bufferedBeacon = count.buffer(2);

bufferedBeacon.add(20); //  equivalent to count.set(20, force: true);

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

See: Beacon.bufferedCount for more details.

Implementation

BufferedCountBeacon<T> buffer(
  int count, {
  String? name,
  bool synchronous = true,
}) {
  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,
  );

  _wrapAndDelegate(beacon, synchronous);

  return beacon;
}