tupleson icon indicating copy to clipboard operation
tupleson copied to clipboard

feat: tsonAsyncGeneratorFunction proposal

Open Sheraff opened this issue 2 years ago β€’ 3 comments

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 generator and collect functions 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).

Sheraff avatar Oct 28 '23 09:10 Sheraff

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

vercel[bot] avatar Oct 28 '23 09:10 vercel[bot]

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 is 72.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%> (ΓΈ)

codecov[bot] avatar Oct 28 '23 09:10 codecov[bot]

@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 πŸ™‚

helmturner avatar Oct 28 '23 10:10 helmturner