runCancellation function

Future<CancellationResult> runCancellation(
  1. CancelToken token,
  2. List<ResourceHandle> handles
)

Runs the cancellation protocol against handles using token. Returns a CancellationResult once the grace period completes.

Implementation

Future<CancellationResult> runCancellation(
  CancelToken token,
  List<ResourceHandle> handles,
) async {
  await token.trigger(handles);

  final disposed = <String>[];
  final leaked = <String>[];
  for (final h in handles) {
    if (token.leaked(h)) {
      leaked.add(h.handleId);
    } else {
      disposed.add(h.handleId);
    }
  }

  return CancellationResult(
    disposedHandles: disposed,
    leakedHandles: leaked,
    timedOut: leaked.isNotEmpty,
  );
}