chore(src/utils): drop unused dbus_helper and monitors modules and cleanup utils code
This commit is contained in:
4 files changed
+2
-213
No files matched your search
@@ -1,36 +1,9 @@
|
||||
import asyncio
|
||||
import functools
|
||||
import typing as t
|
||||
|
||||
from fabric.utils import GLib
|
||||
|
||||
|
||||
def debounce(delay: float) -> t.Callable[..., t.Any]:
|
||||
def decorator(func: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
||||
task: asyncio.Task[None] | None = None
|
||||
|
||||
@functools.wraps(func)
|
||||
async def wrapper(*args: t.Any, **kwargs: t.Any) -> None:
|
||||
nonlocal task
|
||||
|
||||
if task is not None and not task.done():
|
||||
task.cancel()
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
async def delayed_call() -> None:
|
||||
await asyncio.sleep(delay)
|
||||
await func(*args, **kwargs)
|
||||
|
||||
task = asyncio.create_task(delayed_call())
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def sync_debounce(
|
||||
delay: int, min_n_times: int = 0, immediate: bool = False
|
||||
) -> t.Callable[..., t.Any]:
|
||||
|
||||
Reference in new issue
Block a user