runCancellation function
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,
);
}