Skip to content

Create async_await_in_dart.dart #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions async_await_in_dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'dart:async';

const Duration delay = const Duration(milliseconds: 200);

Future loadLastName(String firstName) {
return new Future.delayed(delay).then((_) {
return firstName + 'fest';
});
}

// Marking a function with 'async' will return a future
Future loadLastName2(String firstName) async {
await new Future.delayed(delay);

return firstName + '.com';
}

main() async {
// 'await' will suspend execution of the function until the
var LastName3 = await loadLastName('Hacktober');
var LastName4 = await loadLastName2('Digitalocean');

print('open contribution by Ali in $LastName3');
print('$LastName4');
}