From e31d8ea03c68b55c75ce603e3386503cd8e03363 Mon Sep 17 00:00:00 2001 From: rzvxa Date: Mon, 1 Jan 2024 18:33:06 +0330 Subject: [PATCH] docs: add documentation for deferred function creation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index b079274..79baffd 100644 --- a/README.md +++ b/README.md @@ -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: