This is a POC of being able to stringifying and parsing async values - e.g. `AsyncIterable` / `Promise` etc. I had an evening where my fingers were twitching to hack on something and this idea has been playing in my mind for a while. ### Background / why I'm considering if we should use devalue as the transport in tRPC for any "text based" data instead of JSON. We already support out-of-order responses of batched requests, but it'd be nice to get it combined with a data transformer (devalue, superjson, etc) rather than having our own adapter. It'd also allow devalue on streamed LLM responses etc ### What it does ```js // I want to serialize this and send it over the network as a stream const source = { promise: (async () => { return 'resolved promise' })(), asyncIterable: (async function*() { yield -0 yield 1 yield 2; return 'returned async iterable' })(), }; // ... enter, `stringifyAsyncIterable()` ✨ const stream = stringifyAsyncIterable(source); /** @type {typeof source} */ /// and `parseAsyncIterable` ✨ const result = await parseAsyncIterable(stream) assert.equal(await result.promise, 'resolved promise') const aggregate = [] const iterator = result.asyncIterable[Symbol.asyncIterator]() while (true) { const next = await iterator.next() if (next.done) { assert.equal(next.value, 'returned async iterable') break } aggregate.push(next.value) } assert.equal(aggregate, [-0, 1, 2]); ``` ## Question Would this sort of behavior be of consideration in devalue at all?
This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by KATT and has received 5 comments.