Skip to content
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');
}