No Description

gwillz 044f80d8ce updated test imports and CI to reflect py2 compat 3 years ago
avent 551ea170d3 added py2 compat version of fluid and strict 3 years ago
tests 044f80d8ce updated test imports and CI to reflect py2 compat 3 years ago
.gitignore e692c98fc0 added unit test framework 3 years ago
.gitlab-ci.yml 044f80d8ce updated test imports and CI to reflect py2 compat 3 years ago
MANIFEST.in d40deabb34 added pypi stage to CI 3 years ago
README.md f5a2c77c45 updated readme, version bump 0.7 3 years ago
setup.py f5a2c77c45 updated readme, version bump 0.7 3 years ago
test.py adc9876d59 readme updated 3 years ago

README.md

Asynchronous Events

build status coverage report

This library provides a simple event interface for threaded environments. It's primary aim is to keep processing of events within their respective threads. Although 'threads' in Python are mostly artificial, considering the GIL, this library is still beneficial.

  • handling exceptions within the correct thread
  • clear separation, and therefore understanding, of thread workloads
  • creating async code and loops without requiring asyncio spaghetti

Operation

Avents ties threads to object instances. Therefore threads should target the loop() function of an Abject. If implementing threads in an existing thread loop, then include a if self._handlEvents(): break call.

Any given event handler will be executed within an Abject's thread loop. Avents discovers this by using the instance of a method-function or the first parameter of the fire() function. If neither can be found, the handler is put on the _sub_main event stack that is executed in the run_forever() helper function.

Additional

This library also includes a barebones, async-less, Event class from which Avent inherits its core functionality.

Fluid Events

This is a slight modification of the Event class to allow any number of args for handlers and the fire() function without errors.

from avent import Fluid as Event

ev = Event()
ev += lambda a, b, c: print(a,b,c)
ev += lambda a: print(a)

ev.fire(1, 2)
# handler 1 => "1, 2, None"
# handler 2 => "1"

Strict Events

This is the polar opposite of a 'Fluid' event. Permissible arguments are specific on init and handlers and events will throw ArgsError whenever the rules are broken.

from avent import Strict as Event

ev = Event('a', 'b')

ev += lambda a,b,c: print(a,b,c) # => throws ArgsError
ev += lambda a: print(a)         # => throws ArgsError

ev.fire(1)       # => throws ArgsError
ev.fire(1, 2, 3) # => throws ArgsError

# acceptable
ev += lambda a,b: print(a,b)
ev.fire(1,2)

Authors

Legal

Copyright (c) 2017 MK2 Engineering Solutions Pty. Ltd. All Rights Reserved.