Skip to content

Commit

Permalink
docs: add documentation for deferred function creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jan 1, 2024
1 parent 66318b5 commit e31d8ea
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ And instead, write more readable(in my opinion) code like this:
.await; // or .toPromise();
```

Or you can pass the function itself to the `dwait` function and get a deferred function you can use directly!

```js
const getUserDeferred = dwait(getUserAsync);
const username = await getUserDeferred()
.body
.toJson()
.username
.trim()
.await; // or .toPromise();
```

# Why?
If you have ever seen any async code from `Rust` language you can immediately see the source of inspiration for the `dwait` library.
Most languages have opted-in for writing the `await` keyword before the expression, This way it will read more naturally. For example something like this:
Expand Down

0 comments on commit e31d8ea

Please sign in to comment.