diff --git a/autobahn/twisted/connection.py b/autobahn/twisted/connection.py index 02cad77b..0c8acc86 100644 --- a/autobahn/twisted/connection.py +++ b/autobahn/twisted/connection.py @@ -164,7 +164,7 @@ class Connection(connection.Connection): return transport_endpoint.connect(transport_factory) @inlineCallbacks - def start(self, reactor=None, main=None): + def start(self, reactor=None): if reactor is None: from twisted.internet import reactor @@ -173,8 +173,7 @@ class Connection(connection.Connection): txaio.start_logging(level='debug') - if main: - main(reactor, self) + yield self.fire('start', reactor, self) transport_gen = itertools.cycle(self._transports) diff --git a/examples/twisted/wamp/test_newapi3.py b/examples/twisted/wamp/test_newapi3.py index 58face9c..469f51aa 100644 --- a/examples/twisted/wamp/test_newapi3.py +++ b/examples/twisted/wamp/test_newapi3.py @@ -10,6 +10,7 @@ def main(reactor, connection): print("on_join: {}".format(details)) def add2(a, b): + print("add2() called", a, b) return a + b yield session.register(add2, u'com.example.add2') @@ -21,18 +22,13 @@ def main(reactor, connection): print("error: {}".format(e)) finally: print("leaving ..") - #session.leave() + session.leave() connection.on('join', on_join) - def on_leave(session, details): - print("on_leave: {}".format(details)) - session.disconnect() - - #connection.on('leave', on_leave) - if __name__ == '__main__': - connection = Connection() - react(connection.start, [main]) + connection.on('start', main) + + react(connection.start) diff --git a/examples/twisted/wamp/test_newapi5.py b/examples/twisted/wamp/test_newapi5.py new file mode 100644 index 00000000..024bf7e0 --- /dev/null +++ b/examples/twisted/wamp/test_newapi5.py @@ -0,0 +1,21 @@ +from twisted.internet.task import react +from twisted.internet.defer import inlineCallbacks as coroutine +from autobahn.twisted.connection import Connection + + +@coroutine +def main(reactor, connection): + + transport = yield connection.connect() + session = yield transport.join(u'realm1') + result = yield session.call(u'com.example.add2', 2, 3) + yield session.leave() + yield transport.disconnect() + yield connection.close() + + +if __name__ == '__main__': + connection = Connection() + connection.on('start', main) + + react(connection.start)