feat: tsonAsyncGeneratorFunction proposal
This PR is a proposal for tsonAsyncGeneratorFunction: a serializer that can serialize a generator function and deserialize it into a generator function. This would allow for iterators that can be iterated many times
Pros
- this could be useful in the context of a cached query, read in several places of an app, or at several β times
- this could be useful in the context of react where a component might be re-rendered many times
Cons
- this might encourage bad practices (though I'm not sure what "bad practices" are in the age of streaming) by making it easy to "overly suspend" a component, whereas using a simple iterator would have forced the developper to store the data somewhere on first pass and never suspend again after that
- this might eat up more RAM than a simple iterator because the entire stream is exhausted and its result stored, even if the generator is never read (or only partially read). This could maybe be improved upon by using the
generatorandcollectfunctions as coroutines and only read from the stream when needed... But doing so might also keep the stream open for an unreasonably long time.
Limits
- only a generator function expecting 0 arguments can be serialized (
functionName.length === 0) because on the client side it doesn't contain any logic, only yields data
If the idea seems sound and this is something we want to add to tupleson, I will write more tests (for now, there is only 1 test for the success case, errors/interruptions aren't tested).
The latest updates on your projects. Learn more about Vercel for Git βοΈ
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| tupleson-async | β Ready (Inspect) | Visit Preview | π¬ Add feedback | Oct 28, 2023 9:56am |
Codecov Report
Merging #84 (a4839b5) into main (d190fa6) will decrease coverage by
1.63%. Report is 1 commits behind head on main. The diff coverage is72.36%.
@@ Coverage Diff @@
## main #84 +/- ##
==========================================
- Coverage 94.07% 92.44% -1.63%
==========================================
Files 31 32 +1
Lines 1872 2024 +152
Branches 194 213 +19
==========================================
+ Hits 1761 1871 +110
- Misses 109 151 +42
Partials 2 2
| Flag | Coverage Ξ | |
|---|---|---|
| unit | 92.44% <72.36%> (-1.63%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files | Coverage Ξ | |
|---|---|---|
| src/index.ts | 100.00% <100.00%> (ΓΈ) |
|
| src/async/handlers/tsonAsyncGeneratorFunction.ts | 72.18% <72.18%> (ΓΈ) |
@KATT and I discussed the topic of AGFs at great length during our meeting yesterday, and it was super productive. I really want to respond with a summary of our discussions and a review of this proposal... but apparently I abused my 'e' key and now I can't log in to my computer until I get into the genius bar π
Not sure what your TZ is, but if you're up for meeting this weekend I'd love to try to sync up on this?
Edit: also happy to push to early next week if you don't work the weekends π