Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 2, 2023
1 parent 35ebf8d commit 093bc0d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .rfcs/001-serialize-async.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -66,7 +68,8 @@ function walker(nonce, value) {
},
};

function addPromise(index, promise) {
function registerPromise(promise) {
const index = idx++;
promises.set(
index,
promise
Expand All @@ -77,7 +80,7 @@ function walker(nonce, value) {

function walk(value) {

Check failure on line 81 in .rfcs/001-serialize-async.md

View workflow job for this annotation

GitHub Actions / lint

'value' is defined but never used

Check failure on line 81 in .rfcs/001-serialize-async.md

View workflow job for this annotation

GitHub Actions / lint

'value' is defined but never used
// adds promises if it encounters a promise
addPromise(index, promise);
registerPromise(promise);

Check failure on line 83 in .rfcs/001-serialize-async.md

View workflow job for this annotation

GitHub Actions / lint

'promise' is not defined
}

return [walk(value), iterator];
Expand Down

0 comments on commit 093bc0d

Please sign in to comment.