-
Notifications
You must be signed in to change notification settings - Fork 149
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
chore: Refactor client #1711
chore: Refactor client #1711
Conversation
✅ Deploy Preview for electric-next ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
5a6bf75
to
77b1d1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
I left some comments but nothing major.
Perhaps, let's seek a third opinion (@KyleAMathews ) about the subscribeSync
method vs not having that method and awaiting the callbacks instead (see my comment about that on L338 in client.ts
).
One observation is that the Typescript client is a canonical implementation for other clients to reference. Looking at the source in If we have these two methods, then, both in the source and the website docs (api -> clients -> typescript) it would be good to be clear about why there are two methods, what they do, when to use one over the other and whether this is a common pattern for other clients to follow. |
@thruflo the |
Cool 👍 I guess the "let's make sure we document clearly" point still applies to the alternative solution. |
Extracted out refactoring from #1630
Had to also add asubscribeSync
method onShapeStream
otherwise we cannot guarantee thatShape
is up to date when the stream is up to date, since the processing is done asynchronously. We have three options:1. We re-introduce thePromiseOr
abstractions in order for the singlesubscribe
call to handle both sync and async2. We introduce an explicitsubcsribeSync
like I have done here, which provides strong guarantees on up-to-date synchronicity3. We changeShape
to maintain it's own "up to date" logic as it is not guaranteed that when the stream is up to date that theShape
will have materialized its local state fully, since processing is asyncReintroduced thin version of sync + async handling in the queue to maintain the current API and intended behaviour.
I've discussed with @kevin-dp and we think that actually making the processing callbacks create backpressure on the stream rather than the stream collecting the responses non-stop might be a better API and allow the developers to choose the pace at which the stream will collect data through the choice of processing callback. Will open a new PR for this, so we can merge this one with the refactor.