Merging PR_218 openai_rev package with new streamlit chat app
This commit is contained in:
34
venv/lib/python3.9/site-packages/pydeck/widget/debounce.py
Normal file
34
venv/lib/python3.9/site-packages/pydeck/widget/debounce.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import asyncio
|
||||
|
||||
|
||||
class Timer:
|
||||
def __init__(self, timeout, callback):
|
||||
self._timeout = timeout
|
||||
self._callback = callback
|
||||
self._task = asyncio.ensure_future(self._job())
|
||||
|
||||
async def _job(self):
|
||||
await asyncio.sleep(self._timeout)
|
||||
self._callback()
|
||||
|
||||
def cancel(self):
|
||||
self._task.cancel()
|
||||
|
||||
|
||||
def debounce(wait):
|
||||
def decorator(fn):
|
||||
timer = None
|
||||
|
||||
def debounced(*args, **kwargs):
|
||||
nonlocal timer
|
||||
|
||||
def call_it():
|
||||
fn(*args, **kwargs)
|
||||
|
||||
if timer is not None:
|
||||
timer.cancel()
|
||||
timer = Timer(wait, call_it)
|
||||
|
||||
return debounced
|
||||
|
||||
return decorator
|
||||
Reference in New Issue
Block a user