Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Rodrigo Lopez Peker
2020-08-28 22:16:49 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0b5fbefec6aa07652a9308cc7f2bf100c745ba45
0b5fbefe
1 parent
58d1c602
Work on debouncer.dart
- improved API and docs.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletions
lib/src/state_manager/rx/utils/debouncer.dart
lib/src/state_manager/rx/utils/debouncer.dart
View file @
0b5fbef
import
'dart:async'
;
/// This "function" class is the implementation of [debouncer()] Worker.
/// It calls the function passed after specified [delay] parameter.
/// Example:
/// ```
/// final delayed = Debouncer( delay: Duration( seconds: 1 )) ;
/// print( 'the next function will be called after 1 sec' );
/// delayed( () => print( 'called after 1 sec' ));
/// ```
class
Debouncer
{
final
Duration
delay
;
Timer
_timer
;
Debouncer
({
this
.
delay
});
call
(
void
Function
()
action
)
{
void
call
(
void
Function
()
action
)
{
_timer
?.
cancel
();
_timer
=
Timer
(
delay
,
action
);
}
/// Notifies if the delayed call is active.
bool
get
isRunning
=>
_timer
?.
isActive
??
false
;
/// Cancel the current delayed call.
void
cancel
()
=>
_timer
?.
cancel
();
}
...
...
Please
register
or
login
to post a comment