Futures represent a computation that does not complete immediately. Where a normal function returns a result, an asynchronous function returns a Future that will eventually contain the result. These are similar to Promises in JavaScript. In this lesson, we will learn how to program asynchronously by writing logic to capture values that are returned at a later time.
Thanks for the explanation Jermaine Oppong. One question, what would it be same as Promise.all with Futures in dart lang?
Hey @Hosarsiph, glad I could help. The equivalent would be Future.wait()
:
var a = Future(() => 5);
var b = Future(() => 6);
var c = Future(() => 7);
void main() async {
Future.wait([a, b, c])
.then(print);
}
Learn more here: https://api.dartlang.org/stable/2.3.0/dart-async/Future/wait.html
You can try the snippet on DartPad
Awesome! Thanks.