cross_channel 0.11.0 copy "cross_channel: ^0.11.0" to clipboard
cross_channel: ^0.11.0 copied to clipboard

High-performance & flexible channels for Dart/Flutter.

example/cross_channel_example.dart

import 'package:cross_channel/cross_channel.dart';

Future<void> main() async {
  // 1. MPSC (Multi-Producer Single-Consumer)
  final (mpscTx, _) = XChannel.mpsc<String>(capacity: 100);
  await mpscTx.send('task');

  // 2. MPMC (Multi-Producer Multi-Consumer) - cloned receivers
  final (mpmcTx, mpmcRx0) = XChannel.mpmc<String>(capacity: 10);
  final mpmcRx1 = mpmcRx0.clone();
  print('Consumers: $mpmcRx0, $mpmcRx1');
  await mpmcTx.send('work');

  // 3. OneShot
  final (oneTx, oneRx) = XChannel.oneshot<String>();
  await oneTx.send('reply');
  await oneRx.recv();

  // 4. SPSC (Single-Producer Single-Consumer)
  final (spscTx, _) = XChannel.spsc<int>(capacity: 1024);
  await spscTx.send(42);

  // 5. Broadcast
  final (bcTx, bcAt) = XChannel.broadcast<String>(capacity: 128);
  final sub = bcAt.subscribe(replay: 5);
  print('Subscriber created: $sub');
  await bcTx.send('announcement');
}
0
likes
160
points
479
downloads

Publisher

verified publishermki.dev

Weekly Downloads

High-performance & flexible channels for Dart/Flutter.

Repository (GitHub)
View/report issues

Topics

#concurrency #async #channels #mpsc #mpmc

Documentation

API reference

License

MIT (license)

Dependencies

web

More

Packages that depend on cross_channel