Last active
April 20, 2021 09:07
-
-
Save davidmigloz/529721f6e9317da8740cb9706d0dd6f8 to your computer and use it in GitHub Desktop.
Dart vs Kotlin: async sequential
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
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!"); | |
} |
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 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