Remove duplicated code around waiting for shared work - #5463
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR removes duplicated “shared work waiting” logic by switching remaining call sites to the existing join_task() helper, consolidating the cancellation-safe waiting behavior in one place without changing runtime behavior.
Changes:
- Replaced several instances of
await asyncio.wait((task,)); task.result()withreturn await join_task(task). - Removed duplicated explanatory comments at call sites, keeping only context-specific notes where needed.
- Added
join_taskimports in modules that previously used the inline pattern.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
music_assistant/models/recommendation_payload.py |
Uses join_task() for shared payload fetch/refresh tasks, preserving non-cancelling waiter behavior while reducing duplicated code/comments. |
music_assistant/helpers/util.py |
Updates remaining internal single-flight wait sites to use join_task() (including guard_single_request), centralizing the cancellation-safe wait behavior. |
music_assistant/helpers/images.py |
Switches shared image fetch and thumbnail generation waits to join_task() and imports it. |
music_assistant/helpers/colors.py |
Switches shared palette extraction wait to join_task() and imports it. |
c87b825 to
886cf69
Compare
886cf69 to
98b9e58
Compare
What does this implement/fix?
PR #5453 added a
join_task()helper for waiting on work that is shared between callers. Seven older call sites still had their own copy of exactly the same code, each with the same five-line explanation attached, so the codebase had two ways of doing one thing.These now all use the helper. No behaviour change — the helper does exactly what the inlined code did, and the existing tests pass untouched.
helpers/util.py,helpers/colors.py,helpers/images.pyandmodels/recommendation_payload.pytojoin_task()Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.