2024-01-29 14:06:15 -05:00
|
|
|
# Copyright 2024 (c) Anna Schumaker.
|
|
|
|
"""Our ListenBrainz operation priority queue."""
|
|
|
|
|
|
|
|
|
|
|
|
class Queue:
|
|
|
|
"""A queue for prioritizing ListenBrainz operations."""
|
2024-01-30 16:34:00 -05:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize the task Queue."""
|
|
|
|
self._set_token = None
|
2024-02-13 22:39:46 -05:00
|
|
|
self._now_playing = None
|
2024-01-30 16:34:00 -05:00
|
|
|
|
|
|
|
def clear(self, op: str) -> None:
|
|
|
|
"""Clear a pending operation."""
|
2024-02-13 22:39:46 -05:00
|
|
|
match op:
|
|
|
|
case "clear-token" | "set-token": self._set_token = None
|
|
|
|
case "now-playing": self._now_playing = None
|
2024-01-30 16:34:00 -05:00
|
|
|
|
|
|
|
def push(self, op: str, *args) -> None:
|
|
|
|
"""Push an operation onto the queue."""
|
2024-02-13 22:39:46 -05:00
|
|
|
match op:
|
|
|
|
case "clear-token" | "set-token": self._set_token = (op, *args)
|
|
|
|
case "now-playing": self._now_playing = (op, *args)
|
2024-01-30 16:34:00 -05:00
|
|
|
|
|
|
|
def pop(self) -> tuple:
|
|
|
|
"""Pop an operation off the queue."""
|
2024-02-13 22:39:46 -05:00
|
|
|
if (res := self._set_token) is not None:
|
|
|
|
self._set_token = None
|
|
|
|
elif (res := self._now_playing) is not None:
|
|
|
|
self._now_playing = None
|
2024-01-30 16:34:00 -05:00
|
|
|
return res
|