diff --git a/www/docs/async-rosetta-stone.mdx b/www/docs/async-rosetta-stone.mdx index dec62170..c34a5d92 100644 --- a/www/docs/async-rosetta-stone.mdx +++ b/www/docs/async-rosetta-stone.mdx @@ -201,6 +201,39 @@ function* main() { }; ``` +## `Promise.withResolvers()` \<=> `withResolvers()` + +Both `Promise` and `Operation` can be constructed ahead of time without needing to begin the process that will resolve it. To do this with +a `Promise`, use the `Promise.withResolvers()` function: + +```ts +async function main() { + let { promise, resolve } = Promise.withResolvers(); + + setTimeout(resolve, 1000); + + await promise; + + console.log("done!") +} +``` + +In effection: + +```ts +import { withResolvers } from "effection"; + +function* main() { + let { operation, resolve } = withResolvers(); + + setTimeout(resolve, 1000); + + yield* operation; + + console.log("done!"); +}; +``` + ## `for await` \<=> `for yield* each` Loop over an AsyncIterable with `for await`: