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

Add WithContext methods #192

Merged
merged 4 commits into from
Sep 3, 2024
Merged

Add WithContext methods #192

merged 4 commits into from
Sep 3, 2024

Conversation

PaulSonOfLars
Copy link
Owner

What

Add *WithContext methods when dealing with the telegram API, to ensure that we can set the right deadlines where necessary and tell any long-running methods when they should be cancelled.

Addresses #190

Impact

  • Are your changes backwards compatible? No - some small changes to the BotClient interface; TimeoutContext now takes an optional parent context too.
  • Have you included documentation, or updated existing documentation? Y
  • Do errors and log messages provide enough context? Y

@liuerfire
Copy link
Contributor

LGTM. My code is running good with this branch.

request.go Outdated
// TimeoutContext calculates the required timeout contect required given the passed RequestOpts, and any default opts defined by the BotClient.
TimeoutContext(opts *RequestOpts) (context.Context, context.CancelFunc)
// TimeoutContext wraps the existing context with the timeout from the provided RequestOpts, or any default opts defined by the BotClient.
TimeoutContext(ctx context.Context, opts *RequestOpts) (context.Context, context.CancelFunc)
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, just curious about this method 😄

What's your consideration to define this method separately?
I think we can pass timeout parameter to https://github.com/PaulSonOfLars/gotgbot/blob/v2.0.0-rc.29/bot.go#L42 to achieve the same effect and even if we need ctx to do other things we can do it in RequestWithContext.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Well, two reasons:

  1. bot-wide timeouts
  2. backwards compatibility

I do agree it would be nice if it wasn't part of it at this point! Might look into it to see if it still needs to be part of the interface though...

Copy link
Contributor

Choose a reason for hiding this comment

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

Got. thanks for replying

Copy link
Owner Author

Choose a reason for hiding this comment

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

Managed to clean it up - you were right, doesn't need to be there after all :)

@PaulSonOfLars
Copy link
Owner Author

LGTM. My code is running good with this branch.

Awesome, great to hear - thank you!

@PaulSonOfLars PaulSonOfLars merged commit 1fdf1a9 into v2 Sep 3, 2024
3 checks passed
@PaulSonOfLars PaulSonOfLars deleted the paul/with-context branch September 3, 2024 22:16
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