Python implementation of debounce functionality.
Project description
debounce
Debounced function delays invoking the function until after wait seconds have
elapsed since the last time the debounced function was invoked. The debounced
function comes with a cancel method to cancel delayed function invocations
and a flush method to immediately invoke them.
Additional arguments
leading=True- If you want it to call your function immediately on invocation.max_wait=x- The maximum time the decorated function is allowed to be delayed before it's invoked.
Installation
pip install py-debounce
Usage
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
Cancel
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
# Imagine that the event has been called
handle_event(...)
# You can then cancel it by calling. The function will now never be called.
handle_event.cancel()
Flush
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
# Imagine that the event has been called
handle_event(...)
# You can flush the call to immediately call it.
handle_event.flush()
Asyncio
It also handles async functions.
from debounce import debounce
@debounce(0.1)
async def event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_debounce-0.1.2.tar.gz.
File metadata
- Download URL: py_debounce-0.1.2.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3253fde4bd00c02a0a9cfed72ba02e4a5a353bdf55544eea226b5532e0af20b8
|
|
| MD5 |
8c561d369cd4abb4385ba515d8e9f862
|
|
| BLAKE2b-256 |
d8243d59b20ab8579a9cad675ae36fcae6176448912686e87f3086dd837bae9b
|
File details
Details for the file py_debounce-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_debounce-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d4b3a63d6b9c85851166b68d114f90ef0552d894ba805c37e0e733f394ab516
|
|
| MD5 |
53af035a50f76378e80474bb92c8f59d
|
|
| BLAKE2b-256 |
e5dd53072abbc13429d7b964d59ef0b347a4620de5a2bcefa40b49372e493691
|