send method

  1. @override
Stream<A> send(
  1. M message
)
override

Send a message to the Handler this StreamActor is based on.

The message is handled in another Isolate and the handler's response is sent back asynchronously.

If an error occurs while the Handler handles the message, the returned Stream emits an error, otherwise items provided by the Handler are streamed back to the caller.

Implementation

@override
Stream<A> send(M message) {
  final id = _currentId++;
  final controller = StreamController<A>();
  _answerStream
      .where((m) => m.id == id)
      .takeWhile((m) => m.content != #actors_stream_done)
      .listen((answer) {
    final content = answer.content;
    if (answer.isError) {
      controller.addError(content!, answer.stacktrace);
    } else {
      controller.add(content as A);
    }
  }, onDone: controller.close);
  _sender.then((s) => s.send(Message(id, message)));
  return controller.stream;
}