Skip to content

Commit

Permalink
doc: update docs/dart.md (#814)
Browse files Browse the repository at this point in the history
### Current behavior
The current asynchronous login sample code has the following issues:
1. The `main` function tries to use `await userName()`, but `userName` is a string variable, not a function.
2. the `login` function should be called and `await` should be used to wait for its result.
### Expected behavior
The `main` function should correctly call the `login` function and use `await` to wait for the result, then print out the username.
### Sample code
Here is the corrected code:
```dart
Future<String> login() {
String userName = "Temidjoy";
return Future.delayed(
Duration(seconds: 4), () => userName
).
}
main() async {
print('Authenticating please wait...') The
String result = await login();
String result = await login(); print(result);
}
  • Loading branch information
openapphub authored Aug 15, 2024
1 parent 8963525 commit f0da2a3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/dart.md
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,8 @@ Future<String> login() {
// 异步
main() async {
print('Authenticating please wait...');
print(await userName());
String result = await login();
print(result);
}
```

Expand Down

0 comments on commit f0da2a3

Please sign in to comment.