-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New subscription-based adapters #5731
base: next
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
@domlen2003 is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
Somehow it fails on client build, where I changed nothing? |
Okay i think there is actually some help needed with setting up the build for cloudflare worker types and e2e tests with a worker emulation. |
Also im currently running into a wall with DO I/O: |
This is very exciting - could you share some details on how we'd test this? I've never actually used the CF stuff here but I'm open to adding an adapter Got limited time over the next week to play with this |
Also as an FYI, we got #5713 pending which adds support for SSE and for subscriptions to be generator functions rather than our own observable thing. I don't know if CF has something to support SSE well but that'd be quite exciting |
Switching from the obervables would be a huge improvement imho, currently I recreate the subscription by sending it an empty dummy message. This is actually not optimal as it breaks the guaranty of the subscription message to be non null (if specified by the router). Im fairly sure cloudflare doesn't support SSE on workers or durable objects. I don't know any of the reasoning behind it but probably they deemed it not useful enough since they made pretty good performance advancements with websocket hibernation. |
Well cloudflare has an (experimantal?) vitest integration tho so far i wasn't successfull in integrating it with the current test harness. Also i have quite limited experience with rollup and struggle with setting up the 'cloudflare:workers' imports correctly. In terms of which test are needed, I think we mainly need to focus on the hibernation/wakeup problem which also currently causes the I think we could have an actual chance of cloudflare devs helping us out with these more specific problems, since their generally very "typing-affine" and sometimes take up projects like these in their free time (see workers-rs). |
CloudFlare Workers do support SSE, you have to pass a ReadSteam inside of the response object that you return and you can write to this. CloudFlare limits workers to 50ms of CPU time, if you exceed this limit the worker gets terminated. https://developers.cloudflare.com/workers/runtime-apis/streams/ Working demo: Events come in for about 2 hours using just an interval, so the request can be pretty long running. |
Okay thats interesting, but would we be able to hold it for longer in a Durable Object? |
Those are voodoo, words to me :)) I have in the past attempted to implement subscriptions with CF workers, but I realised that it would be way to expensive if I didn't make use of hibernation, and I couldn't wrap my head around how that worked, so I gave up π¬. |
CF hibernation is the most powerful (it delivers messages in real-time) and cost-efficient method. Any other method will be limited in features or costly in terms of CPU time. |
Yes thats my opinion too, I would recommend focussing on the hibernation websocket API since this would be the most cost effective. |
From the code that I have read in #5713, SSE subscriptions should work out of the box with CloudFlare workers, however I couldn't get the repo to install to test it properly. |
It seems i have a working example rn. It actually survives hibernation and resusbcribes. Tho it's completely untested. |
# Conflicts: # packages/server/src/adapters/subscribable/base.ts # packages/server/src/adapters/subscribable/ws.ts
Closes #
π― Changes
ws
adapter on top of the base utilscloudflare-durable-objects
adapterβ Checklist