Skip to content

Instantly share code, notes, and snippets.

@denya
Created January 26, 2022 22:07
Show Gist options
  • Save denya/b288d51994f65e3ae6d7698397cd3954 to your computer and use it in GitHub Desktop.
Save denya/b288d51994f65e3ae6d7698397cd3954 to your computer and use it in GitHub Desktop.
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