IsolateEffectHandler<Effect, Msg> class abstract base

An EffectHandler implementation that processes effects in a separate isolate.

This handler offloads effect processing to a separate isolate, allowing computationally expensive or blocking tasks to run without affecting the main thread. It is particularly useful for tasks like heavy computations, parsing, or file I/O that benefit from parallelism provided by isolates.

Key Features:

  • Isolate-based execution: Effects are processed in an independent isolate.
  • Message emission: Allows the handler to emit messages back to the main isolate.
  • Encapsulation: Abstracts away the complexity of managing isolates.

Example:

final class MyEffectHandler extends IsolateEffectHandler<MyEffect, MyMsg> {
  @override
  Future<void> handle(MyEffect effect, MsgEmitter<MyMsg> emit) async {
    // Perform expensive work here
    final result = await performHeavyComputation(effect.data);
    emit(MyMsg(result));
  }
}

Note:

  • Each effect is processed in its own isolate, which is spawned and terminated automatically.
  • Because of how isolate works you should be careful, not all object can be send. See SendPort docs.
Implemented types
Annotations
  • @experimental

Constructors

IsolateEffectHandler()
Creates an IsolateEffectHandler.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(Effect effect, MsgEmitter<Msg> emit) Future<void>
Processes the given effect in a separate isolate.
override
handle(Effect effect, MsgEmitter<Msg> emit) FutureOr<void>
Defines the logic for processing the effect within the isolate.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited