start method

  1. @override
Future<void> start(
  1. CancellationToken cancellationToken
)
override

Triggered when the application host is ready to start the service.

Implementation

@override
Future<void> start(CancellationToken cancellationToken) async {
  // Create linked token to allow cancelling executing
  // task from provided token
  _stoppingCts =
      CancellationTokenSource.createLinkedTokenSource([cancellationToken]);

  // Store the operation we're executing
  _executeOperation = CancelableOperation.fromFuture(
    execute(_stoppingCts!.token),
  );

  // If the operation is completed then return it, this will bubble
  // cancellation and failure to the caller
  if (_executeOperation != null) {
    if (_executeOperation!.isCompleted) {
      return _executeOperation!.value;
    }
  }

  // Otherwise it's running
  return Future.value();
}