effect<T> function
Creates and runs an effect.
runneris the function to run as the effect.scheduleris an optional function to schedule the effect run.onStopis an optional function called when the effect is stopped.
final count = ref(0);
effect(() {
print('Count: ${count.value}');
});
count.value = 10; // prints 'Count: 10'
Implementation
public.EffectRunner<T> effect<T>(
T Function() runner, {
void Function()? scheduler,
void Function()? onStop,
}) {
final effect = impl.Effect(
runner,
scheduler: scheduler,
onStop: onStop,
);
try {
effect.run();
} catch (_) {
effect.stop();
rethrow;
}
return impl.EffectRunner(effect);
}