Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 664 Bytes

README.md

File metadata and controls

35 lines (25 loc) · 664 Bytes

AsyncEv: asynchronous event objects

AsyncEv leverages asyncio to create events that can be subscribed to and waited for.

Usage

import asyncio
import asyncev
from dataclasses import dataclass

# Create an event
@dataclass
class MyEvent(asyncev.BaseEvent):
    value: str

# Create a handler
async def on_myevent(ev: MyEvent):
    print(f"Got a MyEvent with the value {ev.value}!")

asyncev.bind(MyEvent, on_myevent)

# Emit event (requires a running asyncio event loop)
async def main():
    asyncev.emit(MyEvent(value="hello world"))
    
asyncio.run(main())

Testing

$ python -m unittest