Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Last active April 20, 2021 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmigloz/529721f6e9317da8740cb9706d0dd6f8 to your computer and use it in GitHub Desktop.
Save davidmigloz/529721f6e9317da8740cb9706d0dd6f8 to your computer and use it in GitHub Desktop.
Dart vs Kotlin: async sequential
Future<String> requestToken() async {
await Future.delayed(Duration(seconds: 1));
return "TOKEN";
}
Future<void> postUserName(String token, String name) async {
await Future.delayed(Duration(seconds: 1));
}
void main() async {
String token = await requestToken();
await postUserName(token, "David");
print("Done!");
}
import kotlinx.coroutines.*
suspend fun requestToken(): String {
delay(1000)
return "TOKEN"
}
suspend fun postUserName(token: String, name: String) {
delay(1000)
}
fun main() = runBlocking {
var token: String = requestToken()
postUserName(token, "David")
println("Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment