exec<T> method

Future<T?> exec<T>(
  1. Future<T> future
)

Implementation

Future<T?> exec<T>(Future<T> future) {
  if (!_enable) {
    return Future<T>.error('This Executor is disable');
  }

  UniqueKey key = UniqueKey();
  CancelableOperation<T> operation =
      CancelableOperation.fromFuture(future, onCancel: () {
    if (_enable) {
      _futures.remove(key);
    }
  });
  _futures.putIfAbsent(key, () => operation);

  operation.value.whenComplete(() {
    if (_enable) {
      _futures.remove(key);
    }
  });
  return operation.valueOrCancellation();
}