unary method

Effect unary(
  1. Bloom target,
  2. void action(
    1. EffectScope scope
    ), {
  3. bool guard()?,
  4. int? take,
  5. void onUncaughtError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Creates an optimized unary manifest Effect attached strictly to a single explicit target providing an EffectScope.

  • Skips initial evaluation (0 runs upon construction/mount).

  • Executes action with an injected EffectScope in an untracked environment when target mutates.

  • Prior to subsequent evaluations or deactivation, the previous turn's EffectScope is marked cancelled and its registered cleanup callbacks are executed in LIFO order.

  • If guard is provided and returns false, execution is skipped and take tickets are preserved.

  • If take is provided, executes at most take times and then automatically deactivates (Early Teardown).

  • If onUncaughtError is provided, it is invoked on uncaught exceptions.

  • target: The single Bloom node to monitor.

  • action: The untracked callback receiving an EffectScope to execute when target mutates.

  • guard: Optional boolean predicate gating execution.

  • take: Optional limit on execution count before automatic deactivation.

  • onUncaughtError: Optional error recovery handler.

Requires:

  • If take is provided, it must be greater than or equal to 0.

Ensures:

  • Returns an optimized unary scoped Effect bound to target.

Throws:

Examples

final room = blooming('lobby');
final e = Effect.scoped.unary(room.bloom, (scope) {
  final client = connect(untracked(room.bloom));
  scope.onCleanup(client.close);
});

Implementation

@pragma('vm:prefer-inline')
Effect unary(
  Bloom target,
  void Function(EffectScope scope) action, {
  bool Function()? guard,
  int? take,
  void Function(Object error, StackTrace stackTrace)? onUncaughtError,
}) =>
    _HandledUnaryManifestEffect(
      target,
      action,
      guard: guard,
      take: take,
      onUncaughtError: onUncaughtError,
    );