diff options
author | Chase Sterling <chase.sterling@gmail.com> | 2022-02-07 19:40:05 -0500 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2022-05-17 22:15:55 +0100 |
commit | 47e548fdb5fed54a8e607ece81ad9f862d96b64a (patch) | |
tree | 186d5389075a6dda5b98ceb86c8d37b644acb006 /deluge/core/core.py | |
parent | cd63efd93557d04c0e3570fa89b338696811c8e0 (diff) | |
download | deluge-47e548fdb5fed54a8e607ece81ad9f862d96b64a.tar.gz deluge-47e548fdb5fed54a8e607ece81ad9f862d96b64a.tar.bz2 deluge-47e548fdb5fed54a8e607ece81ad9f862d96b64a.zip |
[Core] Refactor prefetch_metadata for more clarity
Just trying to clean up some of the more complicated callback logic.
Notable changes:
* The test was awaiting a DeferredList. By default that will eat
exceptions and just add them to the result list (including test
assertion exceptions.) Added fireOnOneErrback=True to make sure that
wasn't happening. * Moved the logic for multiple calls to await the
same response into torrentmanager from core, so no matter where the
prefetch is called from it will wait for the original call.
* Implemented the multiple calls with an explicit queue of waiting
callbacks, rather than a callback callback chain. * Moved to one inline
async function rather than split into a main and callback after alert
function.
* Added some more type hints to the stuff I changed.
Adjusted test since we are using prefetch as an async function now
we have to schedule the alert to come after we start awaiting the
prefetch call.
Closes: https://github.com/deluge-torrent/deluge/pull/368
Diffstat (limited to 'deluge/core/core.py')
-rw-r--r-- | deluge/core/core.py | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/deluge/core/core.py b/deluge/core/core.py index 18fda68b2..35cf0194f 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -432,9 +432,10 @@ class Core(component.Component): return d @export - def prefetch_magnet_metadata( + @maybe_coroutine + async def prefetch_magnet_metadata( self, magnet: str, timeout: int = 30 - ) -> 'defer.Deferred[Tuple[str, bytes]]': + ) -> Tuple[str, bytes]: """Download magnet metadata without adding to Deluge session. Used by UIs to get magnet files for selection before adding to session. @@ -446,19 +447,10 @@ class Core(component.Component): timeout: Number of seconds to wait before canceling request. Returns: - A tuple of (torrent_id (str), metadata (str)) for the magnet. - """ + A tuple of (torrent_id, metadata) for the magnet. - def on_metadata(result, result_d): - """Return result of torrent_id and metadata""" - result_d.callback(result) - return result - - d = self.torrentmanager.prefetch_metadata(magnet, timeout) - # Use a separate callback chain to handle existing prefetching magnet. - result_d = defer.Deferred() - d.addBoth(on_metadata, result_d) - return result_d + """ + return await self.torrentmanager.prefetch_metadata(magnet, timeout) @export def add_torrent_file( |