cancel method

  1. @override
Future<bool> cancel(
  1. String operationId
)
override

Asks the host to abandon the operation with operationId.

Answers whether an operation was still running. false means it had already finished — its real outcome is on its own future, and nothing was interrupted.

Implementation

@override
Future<bool> cancel(String operationId) async {
  final _Operation<Object>? operation = _inFlight[operationId];
  if (operation == null) {
    // Already answered, or never started. Either way there is nothing to
    // interrupt, and saying so is more useful than pretending.
    return false;
  }

  operation.cancelRequested = true;

  try {
    final bool? wasRunning = await channel.invokeMethod<bool>(
      EcrMethods.cancel,
      <String, Object?>{EcrArgs.operationId: operationId},
    );
    return wasRunning ?? false;
  } on PlatformException {
    // The host could not be asked to stop. The operation's own future still
    // settles on whatever the host eventually says, or on its timeout.
    return false;
  } on MissingPluginException {
    return false;
  }
}