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

feat: tsonAsyncGeneratorFunction proposal #84

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Oct 28, 2023

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).

@vercel
Copy link

vercel bot commented Oct 28, 2023

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

@Sheraff Sheraff changed the title feat: tsonAsyncGeneratorFunction proposal for 'iterators that can be iterated many times' feat: tsonAsyncGeneratorFunction proposal Oct 28, 2023
@Sheraff Sheraff requested a review from KATT October 28, 2023 09:35
@codecov
Copy link

codecov bot commented Oct 28, 2023

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%) ⬇️

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%> (ø)

@helmturner
Copy link
Contributor

helmturner commented Oct 28, 2023

@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 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants