Compare commits
4 Commits
668c486068
...
e08b47260f
Author | SHA1 | Date |
---|---|---|
Nocturn9x | e08b47260f | |
Nocturn9x | d83317d34a | |
Nocturn9x | 3f6d3c539f | |
Mattia | bcdb32d8e5 |
|
@ -8,7 +8,7 @@ asyncevents is a small library to help developers perform asynchronous event han
|
||||||
- Built-in exception handling (optional)
|
- Built-in exception handling (optional)
|
||||||
- The public API is fully type hinted for those sweet, sweet editor suggestions
|
- The public API is fully type hinted for those sweet, sweet editor suggestions
|
||||||
- Public API is fully documented (and some private stuff too): you could write this from scratch in a couple of hours (like I did)
|
- Public API is fully documented (and some private stuff too): you could write this from scratch in a couple of hours (like I did)
|
||||||
- Very small (~200 CLOC), although it can't fit on a postcard
|
- Very small (<800 CLOC), although it can't fit on a postcard
|
||||||
- Oneshot events (i.e. fired only once)
|
- Oneshot events (i.e. fired only once)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ from enum import Enum, auto, EnumMeta
|
||||||
class ContainsEnumMeta(EnumMeta):
|
class ContainsEnumMeta(EnumMeta):
|
||||||
"""
|
"""
|
||||||
Simple metaclass that implements
|
Simple metaclass that implements
|
||||||
the item in self operation
|
the 'item in self' operation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __contains__(cls, item):
|
def __contains__(cls, item):
|
||||||
|
@ -38,8 +38,8 @@ class ExceptionHandling(Enum, metaclass=ContainsEnumMeta):
|
||||||
to be caught
|
to be caught
|
||||||
"""
|
"""
|
||||||
|
|
||||||
IGNORE: "ExceptionHandling" = auto() # The exception is caught and ignored
|
IGNORE: "ExceptionHandling" = auto() # The exception is caught and ignored
|
||||||
LOG: "ExceptionHandling" = auto() # The exception is caught and logged
|
LOG: "ExceptionHandling" = auto() # The exception is caught and logged
|
||||||
PROPAGATE: "ExceptionHandling" = auto() # The exception is not caught at all
|
PROPAGATE: "ExceptionHandling" = auto() # The exception is not caught at all
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ class UnknownEventHandling(Enum, metaclass=ContainsEnumMeta):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
IGNORE: "UnknownEventHandling" = auto() # Do nothing
|
IGNORE: "UnknownEventHandling" = auto() # Do nothing
|
||||||
LOG: "UnknownEventHandling" = auto() # Log it as a warning
|
LOG: "UnknownEventHandling" = auto() # Log it as a warning
|
||||||
ERROR: "UnknownEventHandling" = auto() # raise an UnknownEvent error
|
ERROR: "UnknownEventHandling" = auto() # raise an UnknownEvent error
|
||||||
|
|
||||||
|
|
||||||
class ExecutionMode(Enum, metaclass=ContainsEnumMeta):
|
class ExecutionMode(Enum, metaclass=ContainsEnumMeta):
|
||||||
|
@ -63,5 +63,5 @@ class ExecutionMode(Enum, metaclass=ContainsEnumMeta):
|
||||||
spawns tasks
|
spawns tasks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PAUSE: "ExecutionMode" = auto() # Spawn tasks via "await"
|
PAUSE: "ExecutionMode" = auto() # Spawn tasks via "await"
|
||||||
NOWAIT: "ExecutionMode" = auto() # Use asyncio.create_task
|
NOWAIT: "ExecutionMode" = auto() # Use asyncio.create_task
|
||||||
|
|
|
@ -56,8 +56,7 @@ class AsyncEventEmitter:
|
||||||
are started according to their priorities, but once they are started they are handled by asyncio's
|
are started according to their priorities, but once they are started they are handled by asyncio's
|
||||||
event loop which is non-deterministic, so expect some disorder). Using ExecutionMode.NOWAIT allows
|
event loop which is non-deterministic, so expect some disorder). Using ExecutionMode.NOWAIT allows
|
||||||
to call the emitter's wait() method, which pauses until all currently running event handlers have
|
to call the emitter's wait() method, which pauses until all currently running event handlers have
|
||||||
completed executing (when ExecutionMode.PAUSE is used, wait() is a no-op), but note that return
|
completed executing (when ExecutionMode.PAUSE is used, wait() is a no-op)
|
||||||
values from event handlers are not returned
|
|
||||||
:type mode: ExecutionMode
|
:type mode: ExecutionMode
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -176,7 +175,7 @@ class AsyncEventEmitter:
|
||||||
# list of tuples. Each tuple in the list contains
|
# list of tuples. Each tuple in the list contains
|
||||||
# a priority (defaults to 0), the insertion time of
|
# a priority (defaults to 0), the insertion time of
|
||||||
# when the handler was registered (to act as a tie
|
# when the handler was registered (to act as a tie
|
||||||
# breaker for _tasks with identical priorities or
|
# breaker for tasks with identical priorities or
|
||||||
# when priorities aren't used at all) a coroutine
|
# when priorities aren't used at all) a coroutine
|
||||||
# function object and a boolean that signals if the
|
# function object and a boolean that signals if the
|
||||||
# handler is to be deleted after it fires the first
|
# handler is to be deleted after it fires the first
|
||||||
|
@ -405,9 +404,8 @@ class AsyncEventEmitter:
|
||||||
remove_all is True (defaults to False), all occurrences
|
remove_all is True (defaults to False), all occurrences
|
||||||
of the given handler are removed, otherwise only the first
|
of the given handler are removed, otherwise only the first
|
||||||
one is unregistered. Does nothing if the given event is not
|
one is unregistered. Does nothing if the given event is not
|
||||||
registered already and raise_on_missing equals False (the default).
|
registered already. This method does nothing if the given
|
||||||
This method does nothing if the given event exists, but the given
|
event exists, but the given handler is not registered for it
|
||||||
handler is not registered for it
|
|
||||||
|
|
||||||
:param event: The event name
|
:param event: The event name
|
||||||
:type event: str
|
:type event: str
|
||||||
|
|
6
setup.py
6
setup.py
|
@ -17,8 +17,8 @@ if __name__ == "__main__":
|
||||||
name="asyncevents",
|
name="asyncevents",
|
||||||
version="0.1",
|
version="0.1",
|
||||||
author="Nocturn9x",
|
author="Nocturn9x",
|
||||||
author_email="hackhab@gmail.com",
|
author_email="nocturn9x@nocturn9x.space",
|
||||||
description="Asynchronous event handling in modern Python",
|
description="Asynchronous event handling for modern Python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://github.com/nocturn9x/asyncevents",
|
url="https://github.com/nocturn9x/asyncevents",
|
||||||
|
@ -26,7 +26,7 @@ if __name__ == "__main__":
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
"License :: OSI Approved :: Apache License 2.0",
|
"License :: OSI Approved :: Apache Software License",
|
||||||
],
|
],
|
||||||
python_requires=">=3.8",
|
python_requires=">=3.8",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue