afterYield method

Future<void> afterYield(
  1. StreamController<Object?> controller
)

What a yield waits on after adding its value.

One microtask first, so the value is delivered and a consumer that pauses on receipt — a StreamIterator, which is what await for uses — has done so before the body looks. Then it waits for as long as the subscription stays paused, which is what async* backpressure is. A cancellation, before or during the wait, completes it with GeneratorCancelledSignal.

Implementation

Future<void> afterYield(StreamController<Object?> controller) async {
  await Future<void>.microtask(() {});
  while (!cancelled && controller.isPaused) {
    await (_resume ??= Completer<void>()).future;
  }
  if (cancelled) throw const GeneratorCancelledSignal();
}