forked from release-engineering/pubtools-pulplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make returned futures proxies for cleaner blocking code
This commit makes every future returned by this client into a proxy future. A proxy future can be used as a future, but it will also implicitly proxy attribute and method lookups through to the underlying result of a future. In many cases, this allows blocking code to be written as if futures are not used at all. This is similar in spirit to commit 15eae36, embracing implicit over explicit for cleaner code. Why? ==== APIs in this library are written to return Futures, to enable aggressively concurrent code. However, there remain many cases where concurrency isn't possible or desired, so the APIs are used in a blocking manner. Currently, the authors of such code are penalized by having to add many calls to .result(), making the code noisy. This commit seeks to reduce that noise and make the blocking code more readable, while still fully supporting non-blocking code styles. As an example of why both non-blocking and blocking coding styles should be supported, consider the search_repository API. Two cases where a task might need to search for repositories are: - when uploading a productid cert into a repo, we need to find related repos for the same product and update repo notes there. - when adding or removing RPMs in a repo, we need to search for corresponding UBI repo(s) in need of repopulation Both of these cases can occur during a task which needs to process many other unrelated steps too, which ideally should be handled concurrently; hence, non-blocking makes sense here. But another common case is: - the user has passed a set of repo IDs into a task and we want to perform a certain operation on each repo (e.g. publish; clear-repo) In this case, the desired behavior is generally that we want to fail the task early and not proceed to next steps if any of the passed repo IDs are incorrect. So, we do explicitly want to block on repo search completion, by writing code such as: repos = client.search_repository(...) found_ids = [repo.id for repo in repos] check_ids(requested_ids, found_ids) Hence both blocking and non-blocking usage of search_repository is valid in different contexts. It'd be best if we can cleanly support both. Risks ===== It's not a certainty that the benefits of this change outweigh the disadvantages. Problems which might come up due to this include: - Generally enables devs to be sloppy, to misunderstand what's the return type of various methods, to not consider when we should or shouldn't block. - Might be confusing due to the proxy being incomplete. For example, if a Future would return an empty list, len(f) == 0 is True, but bool(f) is also True since the future is non-None; a behavior difference from a plain empty list. - Since it's now less common that .result() must be called, it might increase the chance that necessary calls are forgotten.
- Loading branch information
Showing
20 changed files
with
102 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
requests | ||
more-executors>=2.2.0 | ||
more-executors>=2.3.0 | ||
six | ||
PyYAML | ||
jsonschema | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.