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

Move CTS closer to its usage #10191

Merged

Conversation

adamPetho
Copy link
Collaborator

Mistake I made in this PR #10174

requestTimeoutCts (3 minutes) started ticking when it still had a 2 minute delay, resulting in an early cancellation.

Even tho the API provider usually respond in less ~10 seconds, it's better to have these CTS in its proper place.

Comment on lines +252 to +254
using CancellationTokenSource requestTimeoutCts = new(ApiRequestTimeout);
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(verificationCancellationToken, item.Token, requestTimeoutCts.Token);

Copy link
Collaborator

Choose a reason for hiding this comment

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

This code looks correct but I would suggest to use this: https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/Extensions/CancellationTokenExtensions.cs

Basically, instead of having the same kind of block repeated again and again, you can replace it with this:
c# using var linkedCts = verificationCancellationToken.CreateLinkedTokenSourceWithTimeout(ApiRequestTimeout);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't know this extension method existed. Ty, I will keep this in mind for the future.

But here I need to link 3 different cancellation token together, the extension method doesn't help to make the code prettier in this method IMO.

@lontivero
Copy link
Collaborator

It changed the behavior but I think this one is better than the one before.

@lontivero lontivero merged commit 0b8bcd4 into zkSNACKs:master Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants