cancelableFuture method

  1. @protected
Future? cancelableFuture(
  1. Future inner, {
  2. String? tag,
  3. bool needCheckConnection = true,
  4. bool needHandleError = true,
})

Wrap cancelable async process with connection status - needCheckConnection and error process if need - needHandleError.

Implementation

@protected
Future? cancelableFuture(
  Future inner, {
  String? tag,
  bool needCheckConnection = true,
  bool needHandleError = true,
}) async {
  final preProcess =
      needCheckConnection ? () async => checkConnection() : null;
  final process = _processCancelableFuture(inner, preProcess: preProcess);
  return needHandleError
      ? process?.onError(
          (error, stackTrace) {
            if (error is Exception) {
              handleError(error, tag: tag);
            }
          },
        )
      : process;
}