Last active
April 23, 2020 17:11
-
-
Save pascencio/b48aa21555776e90b2c897e93f8224dc to your computer and use it in GitHub Desktop.
Dart Futures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
Future<String> httpGet(String url) { | |
int numeroDeLaSuerte = new Random().nextInt(100); | |
int delay = new Random().nextInt(10); | |
return Future.delayed(new Duration(seconds: delay), | |
() => "Hola tu número de la suerte es: ${numeroDeLaSuerte}"); | |
} | |
void main() async { | |
print('Estamos a punto de pedir todos'); | |
httpGet('https://api.nada.com/aliens') | |
.then((data) => print('Respuesta: ${data}')); | |
String data = await httpGet('https://api.nada.com/aliens'); | |
print('Respuesta: ${data}'); | |
print('Ultima línea'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment