diff --git a/lib/implementations/debounce_lang_tool_service.dart b/lib/implementations/debounce_lang_tool_service.dart index e83c215..ec03d37 100644 --- a/lib/implementations/debounce_lang_tool_service.dart +++ b/lib/implementations/debounce_lang_tool_service.dart @@ -9,7 +9,7 @@ class DebounceLangToolService extends LanguageCheckService { final LanguageCheckService baseService; /// A debouncing used to debounce the API calls. - final Debouncing debouncing; + final Debouncing>?>> debouncing; /// Creates a new instance of the [DebounceLangToolService] class. DebounceLangToolService( @@ -18,17 +18,12 @@ class DebounceLangToolService extends LanguageCheckService { ) : debouncing = Debouncing(duration: debouncingDuration); @override - Future>> findMistakes(String text) async { - final value = - await debouncing.debounce(() => baseService.findMistakes(text)) - as Result>; - - return value; - } + Future>?> findMistakes(String text) async => + await debouncing.debounce(() => baseService.findMistakes(text)); @override Future dispose() async { - await debouncing.close(); + debouncing.close(); await baseService.dispose(); } } diff --git a/lib/implementations/throttling_lang_tool_service.dart b/lib/implementations/throttling_lang_tool_service.dart index ece37db..5b851d0 100644 --- a/lib/implementations/throttling_lang_tool_service.dart +++ b/lib/implementations/throttling_lang_tool_service.dart @@ -10,7 +10,7 @@ class ThrottlingLangToolService extends LanguageCheckService { final LanguageCheckService baseService; /// A throttling used to throttle the API calls. - final Throttling throttling; + final Throttling>?>> throttling; /// Creates a new instance of the [ThrottlingLangToolService] class. ThrottlingLangToolService( @@ -19,18 +19,12 @@ class ThrottlingLangToolService extends LanguageCheckService { ) : throttling = Throttling(duration: throttlingDuration); @override - Future>?> findMistakes(String text) async { - final future = throttling.throttle(() => baseService.findMistakes(text)) - as Future>?>?; - - if (future == null) return null; - - return future.then((res) => res ?? Result.success([].toList())); - } + Future>?> findMistakes(String text) async => + throttling.throttle(() => baseService.findMistakes(text)); @override Future dispose() async { - await throttling.close(); + throttling.close(); await baseService.dispose(); } } diff --git a/pubspec.yaml b/pubspec.yaml index de4706a..ed96e8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: flutter: sdk: flutter http: ^1.0.0 - throttling: ^1.0.0 + throttling: ^2.0.1 dev_dependencies: flutter_test: