Skip to content

Commit

Permalink
[core]: Improve performance of coroutines/tasks and fix event.stop()
Browse files Browse the repository at this point in the history
Fixes #136 and #86
  • Loading branch information
prologic committed Jan 23, 2017
1 parent 70080ac commit be1a2b9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
5 changes: 4 additions & 1 deletion circuits/core/manager.py
Expand Up @@ -674,7 +674,10 @@ def _dispatcher(self, event, channels, remaining): # noqa
if isinstance(value, GeneratorType):
event.waitingHandlers += 1
event.value.promise = True
self.registerTask((event, value, None))
task = (event, value, None)
self.registerTask(task)
# Process the task immediately
self.processTask(*task)
else:
event.value.value = value

Expand Down
48 changes: 48 additions & 0 deletions tests/core/test_call_stop.py
@@ -0,0 +1,48 @@
#!/usr/bin/env python
from __future__ import print_function

import pytest

from circuits import handler, Component, Event


class test(Event):
"""test Event"""

success = True


class foo(Event):
"""foo Event"""


class App(Component):

@handler("test", priority=1)
def on_test(self, event):
event.stop()
yield

@handler("test")
def on_test_ignored(self):
return "Hello World!"


@pytest.fixture
def app(request, manager, watcher):
app = App().register(manager)
assert watcher.wait("registered")

def finalizer():
app.unregister()

request.addfinalizer(finalizer)

return app


def test_call_stop(manager, watcher, app):
x = manager.fire(test())
assert watcher.wait("test_success")

assert x.value is None
2 changes: 0 additions & 2 deletions tests/core/test_generator_value.py
Expand Up @@ -32,7 +32,6 @@ def test_return_generator():

v = app.fire(test())
app.tick()
app.tick()

x = v.value
assert x == "Hello"
Expand All @@ -46,7 +45,6 @@ def test_yield():
v = app.fire(hello())
app.tick()
app.tick()
app.tick()

x = v.value
assert x == ["Hello ", "World!"]

0 comments on commit be1a2b9

Please sign in to comment.