-
Notifications
You must be signed in to change notification settings - Fork 309
backoff: Make duration bounds customizable #975
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
Conversation
lib/api/backoff.dart
Outdated
/// The actual duration will vary randomly up to this value; see [wait]. | ||
static const firstBound = Duration(milliseconds: 100); | ||
|
||
/// The maximum bound on the duration of each wait, even after many waits. |
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.
nit: Should we mention explicitly that this, and firstBound
are upper bounds on the first line, respectively? I feel that these are the first reads for one when looking at the BackoffMachine
interface.
Sorry for the delay! Posted a comment. This LGTM overall. |
This field is initialized but never looked at thereafter. So we can just cut it. It looks like it was never used in the previous history of this file, nor in the history of the corresponding code in zulip-mobile. Presumably it was left over from an earlier draft of that zulip-mobile implementation.
This code was originally adapted from an implementation in JavaScript (from zulip-mobile), and followed that implementation in representing durations mostly as doubles in milliseconds. Before making other changes here, and in particular exposing some of these durations in the class's API, let's adapt it more fully to Dart idioms and norms.
… body The use of an expression body (with `=>`) in this situation is forbidden in the upstream Flutter style guide: https://github.com/flutter/flutter/blob/e6c955416da/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods https://github.com/flutter/flutter/blob/e6c955416da/docs/contributing/Style-guide-for-Flutter-repo.md#use--for-getters-and-callbacks-that-just-return-literals-or-switch-expressions and I've regularly asked in code reviews to replace such things with block bodies. Apparently I hadn't yet absorbed that point, though, when I wrote this code earlier this year. And then just now I was rereading it in order to refactor it, and found I had to visually scan the test's code several times in order to see its overall structure. Fix that.
Also make an editing pass over the [BackoffMachine.wait] doc.
Thanks for the reviews! Merging, with that tweak. |
This will let us have some backoff loops that back off more patiently than others, e.g. because their work is happening in the background and isn't expected to be something the user is already waiting for.
In particular I plan to use this for backing off the fetch of server emoji data, for #669.