new Api
This commit is contained in:
parent
571e282287
commit
ecfe1e8b9c
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue