Simple to use Utilities package for creating EventEmitters and implementing data observers.
Project description
Package name: Jevents
- Author: Jaime Loeuf
- License: MIT
- Package Desciption:
- This package contains classes/functions to implement data_observer patterns and use of EventEmitters like those provided by NodeJS runtime and other languages.
- This package does not have any external dependencies.
- Currently this package contains the
- 'Watch' class
- 'wait_for_daemons' function
- Currently lacking more documentation. For now please view test scripts for the different modules to see how to use this Package.
Below is a watered down example on how to use the Watch class. The full version is available inside the test_watch.py script in the 'test' directory.
from Jevents import Watch
from Jevents import wait_for_daemons
# Create a new data variable and store in the watchData object
sensorData = Watch(12)
# The data stored in the object can be accessed via the value property
print(sensorData.value)
# Alternatively it can also be accessed by calling itself with the help of the __repr__
print(sensorData)
# Define a callback function. All callback functions can expect a input parameter of the data watched.
def chicken(data):
print('Chicken nuggets ', data)
# Using __iadd__ magic method to set/append an on_change callback function
sensorData.on_change += chicken
# Add a time delay to simulate real life async operations
sleep(1.4)
# Update the data in the object, this will cause all the callbacks to be called.
sensorData(1)
# Print out the updated value stored in the object.
print(sensorData)
# Add a time delay to simulate real life async operations
sleep(1.4)
# Update the data in the object. Notice nothing happens even when a new value is being set.
sensorData(5)
# Print out the updated value stored in the object.
print(sensorData)
# Call the wait function to stop main thread from ending before the daemonic threads finnish
wait_for_daemons()
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
Jevents-1.1.3.tar.gz
(5.2 kB
view details)
File details
Details for the file Jevents-1.1.3.tar.gz
.
File metadata
- Download URL: Jevents-1.1.3.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87106d55934a4bf9187d8b36636dfccd3b0eee4df8fcd43b14455b311ee8414c |
|
MD5 | cb10b9da7a97a778512360c1a7e94a1e |
|
BLAKE2b-256 | 115a62106b35a6c81bdc3f0ffc43272dd53c5bb83eb75724e09720cd001e6819 |