The missing Python async timer.
Project description
Async timer
This package provides an async timer object, that should have been part of batteries.
Purpose
Sometimes, you need a way to make something happen over and over again at certain times, like updating information or sending reminders. That's where Async Timer comes in. It lets you set up these repeated actions easily.
This package is particularly useful for tasks like automatically updating caches in the background without disrupting the primary application's workflow.
Features
- Zero Dependencies: Written entirely in Python, Async Timer operates independently without needing any external libraries.
- Versatility in Callables: It accommodates various callable types, including:
- Synchronous functions
- Asynchronous functions
- Synchronous generators
- Asynchronous generators
- Wait for the Next Tick: You can set it up so your program waits for the timer to do its thing, and then continues.
- Keep Getting Updates: You can use it in a loop to keep getting updates every time the timer goes off.
Example Usage
import async_timer
# Simple timer example
timer = async_timer.Timer(12, target=lambda: 42)
timer.start()
val = await timer.join() # `val` will be 42 after 12 seconds
# Async for loop example
import time
with async_timer.Timer(14, target=time.time) as timer:
async for time_rv in timer:
print(f"{time_rv=}") # Prints current time every 14 seconds
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
async_timer-1.0.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for async_timer-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64816c040f4901c8930c6d1a39f82ea94fda7269e5d4ed6c5c6e1fb5364cf5ad |
|
MD5 | 835984798483f4d4f2a338f96bc53826 |
|
BLAKE2b-256 | a5fe7a9114fe219e52b292b1f432efc076a08e551571215e4c8abf279f824cc7 |