Skip to content

Commit efda2fd

Browse files
committed
Add an async/await example in the solution
1 parent aa75dd8 commit efda2fd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ const asyncVar = new AsyncContext.Variable();
201201
// Sets the current value to 'top', and executes the `main` function.
202202
asyncVar.run("top", main);
203203

204-
function main() {
205-
// AsyncContext.Variable is maintained through other platform queueing.
204+
async function main() {
205+
// AsyncContext.Variable is propagated on async/await.
206+
await Promise.resolve();
207+
console.log(asyncVar.get()); // => 'top'
208+
209+
// AsyncContext.Variable is propagated through platform tasks.
206210
setTimeout(() => {
207211
console.log(asyncVar.get()); // => 'top'
208212

0 commit comments

Comments
 (0)