runInIsolate<T, P> method

Future<void> runInIsolate<T, P>(
  1. ZenithNode<AsyncValue<T>> node,
  2. P payload,
  3. T heavyComputation(
    1. P payload
    ), {
  4. ConcurrencyStrategy strategy = ConcurrencyStrategy.concurrent,
})

Runs heavyComputation on a background Isolate via Isolate.run, then writes the result to node via runAsyncGuarded.

Keeps the UI thread free of jank for expensive synchronous work (JSON parsing, crypto, data transforms). heavyComputation and payload must be safe to send across an isolate boundary -- do not close over a ZenithRef, BuildContext, or other non-sendable, mutable state.

Implementation

Future<void> runInIsolate<T, P>(
  ZenithNode<AsyncValue<T>> node,
  P payload,
  T Function(P payload) heavyComputation, {
  ConcurrencyStrategy strategy = ConcurrencyStrategy.concurrent,
}) {
  return runAsyncGuarded<T>(
    node,
    () => Isolate.run(() => heavyComputation(payload)),
    strategy: strategy,
  );
}