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

Three requests at the same time #29

Open
AhmedEzio47 opened this issue Sep 11, 2022 · 1 comment
Open

Three requests at the same time #29

AhmedEzio47 opened this issue Sep 11, 2022 · 1 comment

Comments

@AhmedEzio47
Copy link

The current code makes three requests to 3 different addresses at the same time which is pretty data-consuming, isn't it better to wait for a request to finish, and if it's a failure, try the next?
image

` Future get hasConnection async {
final Completer result = Completer();
int length = addresses.length;

for (final AddressCheckOptions addressOptions in addresses) {
  // ignore: unawaited_futures
  isHostReachable(addressOptions).then(
    (AddressCheckResult request) {
      length -= 1;
      if (!result.isCompleted) {
        if (request.isSuccess) {
          result.complete(true);
        } else if (length == 0) {
          result.complete(false);
        }
      }
    },
  );
}

return result.future;

}`

A small tweak to this function will do the trick.
Thank you.

@gampixi
Copy link
Contributor

gampixi commented Sep 22, 2022

This package just attempts to establish a connection with the given servers, which should have very little overhead. How much data usage are you measuring?

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

2 participants