Nothing Special   »   [go: up one dir, main page]

Skip to content
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

allow cancellation of call using dio cancellation #408

Merged
merged 8 commits into from
Jul 23, 2023

Conversation

rgplvr
Copy link
Contributor
@rgplvr rgplvr commented Jul 7, 2023

allow cancellation of call using dio cancellation

@knaeckeKami knaeckeKami self-assigned this Jul 7, 2023
@knaeckeKami
Copy link
Collaborator

Hello, thanks for the PR. It seems there is an issue with the CI, looks like a breaking change in one of the dependencies of multipack. I'll try to fix it.

Support for cancellation in Dio is good, but is passing a signal cancel token for all requests of the link the right approach?

You can only cancel the token once, right?

I think a better solution would be to pass the cancel token via the context. Then the client code could either create a new cancel token for each request or re-use the same token for multiple requests if preferred.

See e.g. https://github.com/gql-dart/gql/blob/master/links/gql_dio_link/lib/src/dio_link.dart#L312

class DioLinkCancelTokenContextEntry extends ContextEntry {

     final CancelToken token;

     ...
}

in DioLink:

...
final cancelToken = request.context.entry<DioLinkCancelTokenContextEntry>();

...

@rgplvr
Copy link
Contributor Author
rgplvr commented Jul 9, 2023

Makes sense. I have made the changes to push the cancellation token to the context entry.

@knaeckeKami
Copy link
Collaborator

please update your branch from master to fix the ci issues

@rgplvr
Copy link
Contributor Author
rgplvr commented Jul 23, 2023

done

@@ -30,6 +31,7 @@ extension _CastDioResponse on dio.Response {
class DioLink extends Link {
/// Endpoint of the GraphQL service
final String endpoint;
// final dio.CancelToken? cancelToken;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls delete commented leftover code

@@ -66,8 +68,7 @@ class DioLink extends Link {

@override
Stream<Response> request(Request request, [forward]) async* {
final dio.Response<Map<String, dynamic>> dioResponse =
await _executeDioRequest(
final dio.Response<Map<String, dynamic>> dioResponse = await _executeDioRequest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls run dart format

Copy link
Collaborator
@knaeckeKami knaeckeKami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete the commented out code and run dart format

@rgplvr
Copy link
Contributor Author
rgplvr commented Jul 23, 2023

made the changes the source is properly formatted as per the diff

@rgplvr rgplvr requested a review from knaeckeKami July 23, 2023 15:06
@knaeckeKami
Copy link
Collaborator

Thanks, LGTM

@knaeckeKami knaeckeKami merged commit dbb4886 into gql-dart:master Jul 23, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants