Skip to content

Drop request.timer attribute. - #1249

Merged
lovelydinosaur merged 5 commits into
masterfrom
drop-request-timer
Sep 7, 2020
Merged

Drop request.timer attribute.#1249
lovelydinosaur merged 5 commits into
masterfrom
drop-request-timer

Conversation

@lovelydinosaur

@lovelydinosaurlovelydinosaur commented Sep 2, 2020

Copy link
Copy Markdown
Contributor

Minor bit of refactoring. We don't really want a request.timer attribute in our public API, exposing an internal ElapsedTimer instance.

Instead support a Response(..., stream=..., get_elapsed_time=...) parameter, which allows passing in a callable that is used to set response.elapsed when the response is closed. We don't particularly expect our users to need to use this, but it's a little neater and more tightly scoped than having an accessible timer on the request instance.

Also allows us to use a backend-native timer, appropriate to whichever context we're running in.

@lovelydinosaurlovelydinosaur added the refactor Issues and PRs related to code refactoring label Sep 2, 2020

@StephenBrown2StephenBrown2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@florimondmancaflorimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice bit of uncoupling. Left a sanity check question but this looks good!

Comment threadtests/models/test_responses.py
florimondmanca
florimondmanca previously approved these changes Sep 3, 2020
@lovelydinosaur

Copy link
Copy Markdown
ContributorAuthor

Before we merge this, do we think we've got the right name?
Some options might be...

  • get_elapsed_time=...Currently using, in this PR
  • elapsed_timer=...
  • elapsed_callable=...
  • elapsed_time=...
  • elapsed_func=...

Anything else? Which of those is preferable?

@florimondmanca

Copy link
Copy Markdown
Contributor

elapsed_func=...

Yup, I think I prefer this one better. (True that .get_elapsed_time looks like a method rather than an externally-passed argument.)

@florimondmanca
florimondmanca dismissed their stale reviewSeptember 6, 2020 16:02

Wait for elapsed_func

@lovelydinosaur
lovelydinosaur merged commit a783fe5 into masterSep 7, 2020
@lovelydinosaur
lovelydinosaur deleted the drop-request-timer branch September 7, 2020 08:06
@lovelydinosaurlovelydinosaur mentioned this pull request Sep 21, 2020
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactorIssues and PRs related to code refactoring

Development

Successfully merging this pull request may close these issues.

3 participants

@lovelydinosaur@florimondmanca@StephenBrown2