Created
January 26, 2022 22:07
-
-
Save denya/b288d51994f65e3ae6d7698397cd3954 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 { | |
// the only way to get 1.2.3 :))) is await it directly! | |
await sendFBEvent("async", 3); | |
await sendFBEvent("async", 2); | |
await 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