pub fn use_timeout_fn<CbFn, Arg, D>(
callback: CbFn,
delay: D,
) -> UseTimeoutFnReturn<impl Fn(Arg) + Clone + Send + Sync, Arg, impl Fn() + Clone + Send + Sync>
Expand description
Wrapper for setTimeout
with controls.
§Demo
§Usage
let UseTimeoutFnReturn { start, stop, is_pending, .. } = use_timeout_fn(
|i: i32| {
// do sth
},
3000.0
);
start(3);
§SendWrapped Return
The returned closures start
and stop
are sendwrapped functions. They can
only be called from the same thread that called use_timeout_fn
.
§Server-Side Rendering
On the server the callback will never be run. The returned functions are all no-ops and
is_pending
will always be false
.