Skip to content
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

dart complains when trying to return a future #9

Closed
chiptus opened this issue Mar 16, 2024 · 1 comment
Closed

dart complains when trying to return a future #9

chiptus opened this issue Mar 16, 2024 · 1 comment

Comments

@chiptus
Copy link

chiptus commented Mar 16, 2024

Thanks for the work done on this package.

I'm trying to limit calls to https://pub.dev/packages/geocode to 1 per second, because of the API limit.

I created the following class:

class DebouncedGeoCode {
  final GeoCode geoCode = GeoCode();
  final debouncer =
      Debouncing<Address?>(duration: const Duration(milliseconds: 1000));

  Future<Address?> reverseGeocoding(
      {required double latitude, required double longitude}) async {
    return debouncer.debounce(() =>
        geoCode.reverseGeocoding(latitude: latitude, longitude: longitude));
  }
}

dart complains:

The return type 'Future<Address>' isn't a 'Address?', as required by the closure's context.

reversGeocoding returns Future<Address>

@chiptus
Copy link
Author

chiptus commented Mar 16, 2024

I fixed it by using

class DebouncedGeoCode {
  final GeoCode geoCode = GeoCode();
  final debouncer =
      Debouncing<Future<Address>>(duration: const Duration(milliseconds: 1000));

  Future<Address?> reverseGeocoding(
      {required double latitude, required double longitude}) async {
    var response = await debouncer.debounce(() =>
        geoCode.reverseGeocoding(latitude: latitude, longitude: longitude));
    return await response;
  }
}

which makes sense, the debouncer don't need to know if the value is a Future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant