call method
Creates a throttle Effect attached to explicit targets.
Guarantees that action is executed at most once per duration window, preventing
downstream I/O thrashing during high-frequency events.
targets: The collection of reactive Bloom nodes to monitor.duration: The minimum time interval between consecutive executions.action: The untracked callback to execute when triggered.guard: Optional predicate gating execution and preserving tickets when returningfalse.leading: Whether to execute on the leading edge of the time window. Defaults totrue.trailing: Whether to execute on the trailing edge if events arrived during cooldown. Defaults totrue.take: Optional maximum number of times this effect may execute.onUncaughtError: Optional error recovery handler.
Requires:
- At least one of
leadingortrailingmust betrue. - If
takeis provided, it must be greater than or equal to0.
Ensures:
- Returns a throttle Effect attached to
targets.
Throws:
- ArgumentError if both
leadingandtrailingarefalse. - RangeError if
takeis negative.
Examples
final scroll = blooming(0.0);
final e = Effect.throttle(
[scroll.bloom],
const Duration(milliseconds: 100),
() => syncScrollOffset(untracked(scroll.bloom)),
);
Implementation
@pragma('vm:prefer-inline')
Effect call(
Iterable<Bloom> targets,
Duration duration,
void Function() action, {
bool Function()? guard,
bool leading = true,
bool trailing = true,
int? take,
void Function(Object error, StackTrace stackTrace)? onUncaughtError,
}) =>
_ManifestThrottleEffect(
targets,
duration,
action,
guard: guard,
leading: leading,
trailing: trailing,
take: take,
onUncaughtError: onUncaughtError,
);