start method

  1. @useResult
EffectRunner start()

Instantiates an EffectRunner and immediately starts observation and execution.

Ensures:

  • Attaches an active subscription edge to this Effect.
  • Returns an active EffectRunner (isActive == true).

Warning (Anti-Pattern Prevention):

  • Do NOT invoke .start() inside reactive derivations or repeated callbacks without stopping.

BAD:

// [Anti-Pattern] Calling .start() on every derivation pass
final currentCount = computed((via) {
  loggingEffect.start(); // Re-creates and leaks runner
  return via(counter.bloom);
});

GOOD:

// [Recommended] Run standalone effect in service lifecycle
class LoggingService {
  late final EffectRunner _runner;
  void init() => _runner = loggingEffect.start();
  void dispose() => _runner.stop();
}

Examples

final counter = blooming(0);
final loggingEffect = counter.bloom.effect(() => log(untracked(counter.bloom)));
final runner = loggingEffect.start();

// Clean up when finished:
runner.stop();

Implementation

@useResult
@pragma('vm:prefer-inline')
EffectRunner start() => EffectRunner(this)..start();