end method

void end(
  1. C conversation,
  2. NativeTurn turn,
  3. NativeTurnEnd how
)

Records that turn has ended natively. Deletes the conversation first when it was released meanwhile, so whoever waits on NativeTurn.ended — the lock that orders native calls among them — runs after the delete.

Implementation

void end(C conversation, NativeTurn turn, NativeTurnEnd how) {
  if (turn.hasEnded) return;
  turn.nativeCallInFlight = false;
  if (identical(_running[conversation], turn)) _running.remove(conversation);
  try {
    if (turn.deleteWhenEnded) deleteNative(conversation);
  } finally {
    // Whatever the delete did, the lock waiting on this end must go.
    turn._ended.complete(how);
  }
}