throttle method
Defines an explicit rate-limited throttle Effect attached to the scoped targets.
Guarantees that action is executed at most once per duration window across all targets.
duration: The minimum time interval between consecutive executions.action: The untracked callback to execute when triggered.guard: Optional boolean predicate gating execution.leading: Whether to execute on the leading edge of the time window. Defaults totrue.trailing: Whether to execute on the trailing edge if mutations arrived during window. 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 the scoped targets.
Examples
final effect = (scrollX.bloom, scrollY.bloom).effect.throttle(
const Duration(milliseconds: 100),
() => syncViewport(untracked(scrollX.bloom), untracked(scrollY.bloom)),
);
Implementation
@pragma('vm:prefer-inline')
Effect throttle(
Duration duration,
void Function() action, {
bool Function()? guard,
bool leading = true,
bool trailing = true,
int? take,
void Function(Object error, StackTrace stackTrace)? onUncaughtError,
}) =>
Effect.throttle(
_targets,
duration,
action,
guard: guard,
leading: leading,
trailing: trailing,
take: take,
onUncaughtError: onUncaughtError,
);