Skip to content

Commit

Permalink
fix(debounce): only await coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 10, 2024
1 parent 1c9359e commit a875af3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/nrtk_explorer/library/debounce.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from functools import wraps
from trame.app import asynchronous


def debounce(wait, state=None):
Expand All @@ -19,13 +20,16 @@ async def debounced():
await asyncio.sleep(wait)
if state:
with state:
await func(*args, **kwargs)
result = func(*args, **kwargs)
else:
await func(*args, **kwargs)
result = func(*args, **kwargs)

if asyncio.iscoroutine(result):
await result
except asyncio.CancelledError:
pass

task = asyncio.create_task(debounced())
task = asynchronous.create_task(debounced())

return wrapper

Expand Down

0 comments on commit a875af3

Please sign in to comment.