本文整理汇总了Python中emitter.Emitter.once方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter.once方法的具体用法?Python Emitter.once怎么用?Python Emitter.once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emitter.Emitter
的用法示例。
在下文中一共展示了Emitter.once方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_once__3
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_once__3():
"""
Event should be cleaned if no more listeners.
"""
emitter = Emitter()
emitter.once("event", callable)
emitter.emit("event")
assert emitter.events() == set()
示例2: test_once__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_once__4():
"""
Allow updating an event from once() to on().
"""
emitter = Emitter()
emitter.on("event", callable)
emitter.once("event", callable)
emitter.emit("event")
assert callable not in emitter.listeners("event")
示例3: test_once__2
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_once__2():
"""
Listener should be removed after call.
"""
emitter = Emitter()
emitter.once("event", callable)
emitter.on("event", bool)
emitter.emit("event")
assert callable not in emitter.listeners("event")
assert bool in emitter.listeners("event")
示例4: test_once__1
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_once__1():
"""
Listener can be called only once.
"""
emitter = Emitter()
l = []
emitter.once("event", lambda: l.append(1))
emitter.emit("event")
emitter.emit("event")
emitter.emit("event")
assert len(l) == 1
示例5: test_error__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_error__4(spy):
"""
One time listener is removed even if it raises exception.
"""
emitter = Emitter()
emitter.once("event", raise_error)
assert len(emitter.listeners("event")) == 1
emitter.emit("event")
assert len(emitter.listeners("event")) == 0
示例6: test_once__5
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_once__5():
"""
One time listeners should be removed even if an error happens.
"""
emitter = Emitter()
def listener(*args, **kwargs):
raise Exception()
emitter.once("event", listener)
emitter.emit("event")
assert listener not in emitter.listeners("event")
示例7: test_error__5
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [as 别名]
def test_error__5(spy):
"""
One time ERROR listener is removed even if it raises exception.
"""
emitter = Emitter()
emitter.once(Emitter.ERROR, spy.throw)
emitter.on("event", raise_error)
assert len(emitter.listeners(Emitter.ERROR)) == 1
with pytest.raises(Exception):
emitter.emit("event")
assert len(emitter.listeners(Emitter.ERROR)) == 0