-
Notifications
You must be signed in to change notification settings - Fork 14
/
examples.py
56 lines (37 loc) · 1.02 KB
/
examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding: utf-8
# python imports
import os
import sys
# adjust the path to import pymitter
base = os.path.normpath(os.path.join(os.path.abspath(__file__), "../.."))
sys.path.insert(0, base)
# create an EventEmitter instance
from pymitter import EventEmitter
ee = EventEmitter(wildcard=True, new_listener=True, max_listeners=-1)
@ee.on("new_listener")
def on_new(func, event=None):
print("added listener", event, func)
@ee.on("foo")
def handler_foo1(arg):
print("foo handler 1 called with", arg)
@ee.on("foo")
def handler_foo2(arg):
print("foo handler 2 called with", arg)
@ee.on("foo.*", ttl=1)
def handler_fooall(arg):
print("foo.* handler called with", arg)
@ee.on("foo.bar")
def handler_foobar(arg):
print("foo.bar handler called with", arg)
@ee.on_any()
def handler_any(*args, **kwargs):
print("called every time")
print("emit foo")
ee.emit("foo", "test")
print(10 * "-")
print("emit foo.bar")
ee.emit("foo.bar", "test")
print(10 * "-")
print("emit foo.*")
ee.emit("foo.*", "test")
print(10 * "-")