-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Batch link can cancel operations that are in queue or in flight #9248
Conversation
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
After an operation has been subscribed to, and so queued, it is possible to unsubscribe from it, and it will be removed from the queue. Unsubscribing will not impact the debounce, so other operations, if any, will not be delayed by an unsubscription. If a batch of operation is already in flight, and all operations are unsubscribed then the entire XHR will be cancelled. If only some operations are unsubscribed the XHR will be left untouched.
Since BatchHandler is an exported type, it seems appropriate to preserve its optional fields (with their expected types), then override those fields (next, error, complete) with non-optional versions in the QueuedRequest subtype. The field/types of QueuedRequest will end up the same either way.
Since ECMAScript Set and Map preserve the order of their keys (by order of first insertion), they can often be used to keep track of queues or LRU usage chains, while also supporting constant-time deletion of keys (no need for indexOf/splice).
Since we're already changing the type of this pseudo-private property, it seems like a good idea also to privatize/rename it for real, so we can test the hypothesis "nobody is using this field directly" by trialing these changes in beta releases of Apollo Client v3.6.
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.
Thanks for implementing this functionality and adding tests @PowerKiKi!
I started making a few tweaks and got perhaps a little carried away (not everything I changed is in direct response to your code, just general cleanup). That said, please let me know if anything I added doesn't look right to you. Otherwise I'll merge this into release-3.6
and publish another beta release soon (this week) so you can try it out.
Because those are never used inside this project, and they are very likely to break our indices based callback calls and throw an `server returned results with length...`.
I did a new series of (small) commits. IMHO it address all things we said until now, and it could be final reviewed/merged. |
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.
Thanks all!
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
…cel" This reverts commit cefd24c, reversing changes made to d98f1de. I plan to publish this version in the next v3.7.0 beta release, then immediately reinstate most of this functionality, with a narrower attempt to solve issue #9773 in a follow-up beta release, to allow folks to compare the behavior of those two versions.
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled.
This is dependent on apollographql/apollo-client#9248, so it is not strictly specific to `apollo-angular`, but it seemed important to ensure that this package does indeed allow to cancel XHR even when batching is enabled. Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com>
After an operation has been subscribed to, and so queued, it is possible
to unsubscribe from it, and it will be removed from the queue.
Unsubscribing will not impact the debounce, so other operations, if any, will
not be delayed by an unsubscription.
If a batch of operation is already in flight, and all operations are unsubscribed
then the entire XHR will be cancelled. If only some operations are unsubscribed
the XHR will be left untouched.
Checklist: