-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to interrupt debounce #874
Comments
@subzero911 method 1. Shows only the results of the last request DateTime _lastSearchTime;
Future<void> _searchPlaces() async {
final searchTime = DateTIme.now();
_lastSearchTime = searchTime;
final result = await networkCall();
if ( _lastSearchTime <= searchTime) {
// show result
}
}; method 2. cancel previous request // use dio.
CancelToken? _token;
Future<void> _searchPlaces() {
// Cancel if there is a previous request
_token?.cancel('cancel');
_token = CancelToken();
dio.get(url, cancelToken: token)
.catchError((DioError err){
if (CancelToken.isCancel(err)) {
print('Request canceled! '+ err.message)
}else{
// handle error.
}
});
}; |
Well, this looks reasonable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a city navigation app, to search for interesting places. I have categories (parks, cinemas, nightclubs, etc.) and a search textfield.
I enter the text and do a debounced search with reaction:
But what if I started typing and decided to change the category, and rapidly tapped to the another category chip?
In this case, I changed the category, but a search for previous category still has been executed.
I need a way to interrupt debounce.
Consider providing some API like
reactionDisposer.cancelScheduledReaction();
The text was updated successfully, but these errors were encountered: