Implement search provider (#201)
* Begin work on search provider * Initial search provider work, organize meson * Initial work on icons * Implement LaunchSearch * Don't hold arbitrary reference to service I don't know why Lollypop does this * Send notification, pad images * Update translations * Fix init_search_term typing
This commit is contained in:
28
cartridges/errors/error_producer.py
Normal file
28
cartridges/errors/error_producer.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from threading import Lock
|
||||
|
||||
|
||||
class ErrorProducer:
|
||||
"""
|
||||
A mixin for objects that produce errors.
|
||||
|
||||
Specifies the report_error and collect_errors methods in a thread-safe manner.
|
||||
"""
|
||||
|
||||
errors: list[Exception]
|
||||
errors_lock: Lock
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.errors = []
|
||||
self.errors_lock = Lock()
|
||||
|
||||
def report_error(self, error: Exception) -> None:
|
||||
"""Report an error"""
|
||||
with self.errors_lock:
|
||||
self.errors.append(error)
|
||||
|
||||
def collect_errors(self) -> list[Exception]:
|
||||
"""Collect and remove the errors produced by the object"""
|
||||
with self.errors_lock:
|
||||
errors = self.errors.copy()
|
||||
self.errors.clear()
|
||||
return errors
|
||||
Reference in New Issue
Block a user