any method

Future<T> any<T>(Iterable<Future<T>> futures)

Returns the result of the first future in futures to complete.

The returned future is completed with the result of the first future in futures to report that it is complete. The results of all the other futures are discarded.

If futures is empty, or if none of its futures complete, the returned future never completes.

Source

static Future<T> any<T>(Iterable<Future<T>> futures) {
  var completer = new Completer<T>.sync();
  var onValue = (T value) {
    if (!completer.isCompleted) completer.complete(value);
  };
  var onError = (error, stack) {
    if (!completer.isCompleted) completer.completeError(error, stack);
  };
  for (var future in futures) {
    future.then(onValue, onError: onError);
  }
  return completer.future;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-async/Future/any.html