perform method

Future<void> perform({
  1. void onDone(
    1. T result
    )?,
  2. void onError(
    1. Object error
    )?,
})

Perform the task in an isolate Optional callbacks for completion and error

Implementation

Future<void> perform({
  void Function(T result)? onDone,
  void Function(Object error)? onError,
}) async {
  await _initWorker();

  try {
    final result = await workerManager.execute<T>(() async {
      return await performTask();
    });

    if (onDone != null) {
      onDone(result);
    }
  } catch (e) {
    if (onError != null) {
      onError(e);
    } else {
      // Default error logging if no callback provided
      print("IsolateTask error: $e");
    }
  }
}