Debounce class
A class that provides a simple mechanism to debounce multiple calls to a synchronous or asynchronous operation. Debouncing is used to limit the number of calls to the same operation within a specific duration.
The class has two methods: sync()
and async()
. The sync()
method runs a
synchronous operation while the async()
method runs an asynchronous
operation. Both methods take a callId
, an operation
to execute, and a
duration
that specifies the wait time before executing the operation.
You can provide optional callbacks to handle different states and outcomes.
The onError
callback handles errors that occur during the operation. The
onWaiting
callback handles waiting states. The onNull
callback handles
null data. The onEmpty
callback handles empty data. The onSuccess
callback
handles the successful completion of the operation.
Constructors
- Debounce()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
async<
T> ({required Object callId, required Future< T> operation, OnError? onError, OnWaiting? onWaiting, OnNull? onNull, OnEmpty? onEmpty, required void onSuccess(T data), Duration duration = const Duration(milliseconds: 1000)}) → void -
Runs an asynchronous operation with a debounce mechanism to limit multiple
calls to the same operation. This method waits for a specified duration
after a call with a specific
callId
has been made before running the operation. -
sync<
T> ({required String callId, required dynamic operation(), OnError? onError, OnWaiting? onWaiting, OnNull? onNull, OnEmpty? onEmpty, required void onSuccess(T data), Duration duration = const Duration(milliseconds: 1000)}) → void -
Runs a synchronous operation with a debounce mechanism to limit multiple
calls to the same operation. This method waits for a specified duration
after a call with a specific
callId
has been made before running the operation.