schedule<T> method

Future<T?> schedule<T>(
  1. FutureOr<T> task(
    1. LevitTaskContext context
    ), {
  2. String? id,
  3. TaskPriority priority = TaskPriority.normal,
  4. TaskConflictPolicy conflictPolicy = TaskConflictPolicy.reject,
  5. int retries = 0,
  6. Duration? retryDelay,
  7. bool useExponentialBackoff = true,
  8. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
  9. TaskCachePolicy<T>? cachePolicy,
  10. void onStart()?,
  11. void onSuccess(
    1. T result
    )?,
  12. void onProgress(
    1. double progress
    )?,
  13. void onCancel()?,
  14. void onEvent(
    1. LevitTaskEvent event
    )?,
  15. LevitTaskMetadata? metadata,
  16. String? debugName,
})

Schedules task and returns only its eventual result.

Use submit when execution identity or per-execution cancellation is required. Cancellation, dropping, and superseding complete with null.

Implementation

Future<T?> schedule<T>(
  FutureOr<T> Function(LevitTaskContext context) task, {
  String? id,
  TaskPriority priority = TaskPriority.normal,
  TaskConflictPolicy conflictPolicy = TaskConflictPolicy.reject,
  int retries = 0,
  Duration? retryDelay,
  bool useExponentialBackoff = true,
  void Function(Object, StackTrace)? onError,
  TaskCachePolicy<T>? cachePolicy,
  void Function()? onStart,
  void Function(T result)? onSuccess,
  void Function(double progress)? onProgress,
  void Function()? onCancel,
  void Function(LevitTaskEvent event)? onEvent,
  LevitTaskMetadata? metadata,
  String? debugName,
}) {
  return submit<T>(
    task,
    id: id,
    priority: priority,
    conflictPolicy: conflictPolicy,
    retries: retries,
    retryDelay: retryDelay,
    useExponentialBackoff: useExponentialBackoff,
    onError: onError,
    cachePolicy: cachePolicy,
    onStart: onStart,
    onSuccess: onSuccess,
    onProgress: onProgress,
    onCancel: onCancel,
    onEvent: onEvent,
    metadata: metadata,
    debugName: debugName,
  ).result;
}