stream_isolate 0.1.0 copy "stream_isolate: ^0.1.0" to clipboard
stream_isolate: ^0.1.0 copied to clipboard

outdated

An isolate wrapper for stream-powered intercommunication.

pub package github stars license MIT

A wrapper class for Isolate that exposes a communication channel using a Stream.

API Reference #

Usage #

To use, call StreamIsolate.spawn with the same types of arguments passed to Isolate.spawn. You can then use the returned instance to subscribe to events published by the isolate:

final streamIsolate = await StreamIsolate.spawn<int>(doWork);
await for (final i in streamIsolate.stream) {
  print(i);
}
Stream<int> doWork(_) async* {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
  yield 5;
}

You can also call StreamIsolate.spawnBidirectional to create an isolate that exposes an additional communication stream for sending messages to the instance:

final streamIsolate = await StreamIsolate.spawnBidirectional<String, int>(doWork);
await for (final i in streamIsolate.stream) {
  print(i);
  streamIsolate.send('received');
}
Stream<int> doWorkWithListener(Stream<String> inc, _) async* {
  inc.listen((msg) => print('from main: $msg'));

  yield 1;
  yield 2;
  yield 3;
  yield 4;
  yield 5;
}
7
likes
0
pub points
56%
popularity

Publisher

unverified uploader

An isolate wrapper for stream-powered intercommunication.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on stream_isolate