stream method

Stream<U> stream(
  1. I input
)

Streams input's updates once listened to; cancelling stops delivery and waits for the worker to finish the request.

Implementation

Stream<U> stream(I input) {
  _check();
  late StreamController<U> controller;
  _Request<R, U>? request;
  controller = StreamController<U>(
    onListen: () {
      try {
        _check();
        request = _send(input, true, controller);
      } catch (error, stack) {
        controller.addError(error, stack);
        unawaited(controller.close());
      }
    },
    onCancel: () async {
      final active = request;
      if (active == null) return;
      active.cancelled = true;
      await active.finished.future;
    },
  );
  return controller.stream;
}