runInIsolate<T, P> method
Future<void>
runInIsolate<T, P>(
- ZenithNode<
AsyncValue< node,T> > - P payload,
- T heavyComputation(
- P payload
- 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,
);
}