run method

  1. @override
Future<void> run(
  1. EffectHandler<Value> handler
)
override

Executes the effect immediately with the supplied handler. Each effect implementation defines how it schedules work, emits values, and registers disposables.

Implementation

@override
Future<void> run(
  EffectHandler<Value> handler,
) {
  if (!handler.guard()) return Future.value();
  late final CancelableOperation cancellable;
  cancellable = CancelableOperation.fromFuture(
    (runInIsolate ? Isolate.run(future) : future()).catchError((Object error, StackTrace stackTrace) {
      assert(
        onError != null,
        "onError should not be null, Unhandled: $error\n$stackTrace",
      );
      return onError!.call(error, stackTrace);
    }),
  ).then(handler.emit);
  handler.register(cancellable);
  return cancellable.value;
}