From 093bc0d7574d79dcab498ad511f215446a75186d Mon Sep 17 00:00:00 2001 From: KATT Date: Mon, 2 Oct 2023 23:13:51 +0200 Subject: [PATCH] cool --- .rfcs/001-serialize-async.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.rfcs/001-serialize-async.md b/.rfcs/001-serialize-async.md index 2286d74b..3b37ae0e 100644 --- a/.rfcs/001-serialize-async.md +++ b/.rfcs/001-serialize-async.md @@ -52,9 +52,11 @@ for await (const chunk of asyncStringify(iterator)) { ```js function walker(nonce, value) { + let idx = 0; // key: index // value: [index, Promise] const promises = new Map(); + // ... once we start looking at async iterators we can look at https://github.com/fraxken/combine-async-iterators/blob/master/index.js const iterator = { async *[Symbol.asyncIterator]() { while (promises.size) { @@ -66,7 +68,8 @@ function walker(nonce, value) { }, }; - function addPromise(index, promise) { + function registerPromise(promise) { + const index = idx++; promises.set( index, promise @@ -77,7 +80,7 @@ function walker(nonce, value) { function walk(value) { // adds promises if it encounters a promise - addPromise(index, promise); + registerPromise(promise); } return [walk(value), iterator];