chunk method

void chunk(
  1. String text
)

Implementation

void chunk(String text) {
  // A consumer timeout poisons the engine but deliberately leaves this
  // native turn and its callback alive. Native may still post chunks before
  // its final callback; dropping them is the only safe action. Writing to
  // the closed controller would throw through the FFI callback and release
  // that callback while native can still invoke it.
  if (turn.hasEnded || _consumerEnded) return;
  if (turn.cancelRequested) _turns.cancel(_conversation);
  if (text.isNotEmpty) _controller.add(text);
}