runIsolateTask<T> method
Future<T?>
runIsolateTask<T>(
- FutureOr<
T> task(), { - String? id,
- TaskPriority priority = TaskPriority.normal,
- int retries = 0,
- Duration? retryDelay,
- bool useExponentialBackoff = true,
- double weight = 1.0,
- void onError(
- Object error,
- StackTrace stackTrace
- TaskCachePolicy<
T> ? cachePolicy, - String? debugName,
Executes a task in a separate Isolate using Isolate.run.
This is ideal for heavy computational tasks that would otherwise block the main isolate. It leverages runTask internally for queueing, reactive status tracking, and retries.
Constraint: The task must be a top-level function or a static method.
Closures that capture state cannot be sent across isolate boundaries.
debugName is an optional name for the isolate, visible in debug tools.
Implementation
Future<T?> runIsolateTask<T>(
FutureOr<T> Function() task, {
String? id,
TaskPriority priority = TaskPriority.normal,
int retries = 0,
Duration? retryDelay,
bool useExponentialBackoff = true,
double weight = 1.0,
void Function(Object error, StackTrace stackTrace)? onError,
TaskCachePolicy<T>? cachePolicy,
String? debugName,
}) {
return runTask(
() => Isolate.run(task, debugName: debugName),
id: id,
priority: priority,
retries: retries,
retryDelay: retryDelay,
useExponentialBackoff: useExponentialBackoff,
weight: weight,
onError: onError,
cachePolicy: cachePolicy,
);
}