Skip to content

Commit 395205f

Browse files
add async functions descriptions
1 parent d156940 commit 395205f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ Small library which leverages the power of modern JavaScript to provide seamless
99

1010
In the world full of APIs, we starting to forget the power of plain JavaScript and how essential patterns eliminate the need in providing new abstractions.
1111

12-
The power of coroutines allows to write code in synchronous style and be able to pause it or partially postpone its execution. This essential idea brought us [Async Functions](https://github.com/tc39/ecmascript-asyncawait) which are already included in the language.
12+
The power of coroutines allows to write code in synchronous style and be able to pause it or partially postpone its execution. This essential idea brought us [Async Functions](https://github.com/tc39/ecmascript-asyncawait) which are already included in the language. Async functions allow us to get rid of complex Promises API and use plain JavaScript instructions.
13+
14+
```javascript
15+
async function doSomethingComplex(data) {
16+
try {
17+
const response = await postData(data);
18+
const status = await getStatus(response.headers.Location);
19+
return status;
20+
} catch (error) {
21+
notify('Unable to perform the action', error);
22+
}
23+
}
24+
```
25+
26+
Since React allows as to treat the UI as a first-class citizen, we can mix both things for the sake of solving problems that are the same in React and in just JavaScript code.
1327

14-
This project tends to use the simplicity of functional React components and the essential mechanism of coroutines to create stateful components with colocation.
1528

1629
## Install
1730

0 commit comments

Comments
 (0)