Created
January 26, 2022 22:05
-
-
Save denya/d7bca3bb7d424140ab1d8a49776fc176 to your computer and use it in GitHub Desktop.
This file contains 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<void> sendEventsAsync() async { | |
// expected output: sync 1, sync 2, sync 3 | |
// because all tasks will run in the same moment | |
sendFBEvent("async", 3); | |
sendFBEvent("async", 2); | |
sendFBEvent("async", 1); | |
} | |
void sendEvents() { | |
// expected output: sync 3, sync 2, sync 1 | |
// because it's gonna be in sync mode, | |
// because sendEvents is not async! | |
// ... but I'm wrong! | |
// Короче, даже вызов синхронного метода из другого синхронного | |
// Который содержит асинхронный код — все равно будет неблокирующим :) | |
sendFBEvent("sync", 3); | |
sendFBEvent("sync", 2); | |
sendFBEvent("sync", 1); | |
} | |
Future<void> sendFBEvent(String name, int value) async { | |
// sleep for value seconds | |
await Future<void>.delayed(Duration(seconds: value)); | |
print("Send FBEvent: $name=$value"); | |
} | |
void main() { | |
print('Run main...'); | |
print("Send events call"); | |
sendEvents(); | |
print("Send eventsAsync call"); | |
sendEventsAsync(); | |
print('Stop main...'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment