You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 7, 2019. It is now read-only.
I was trying to make a supervisor app with async/await and failed.
I can express my thoughts in Python as following code, but i don't know how to do it in Rust.
importasyncioclassApp:
def__init__(self):
self.api=ControlService(self)
self.business=MyBussinessService()
asyncdefserve(self):
awaitasyncio.wait([
self.api.serve(),
self.business.serve()
])
classControlService:
def__init__(self, app):
self.app=appasyncdefserve(self):
whileTrue:
print('[ControlService ] Waiting for user cmd...')
cmd=awaitsimulate_user_request()
print("[ControlService ] Received user cmd: {}".format(cmd))
ifcmd=="reset":
# here we need to mutate the business and get the resultok=self.app.business.reset()
ifok:
passelse:
passelse:
passclassMyBussinessService:
def__init__(self):
self._value=0defreset(self):
self._value=0returnTrueasyncdefserve(self):
whileTrue:
print('[BussinessService ] Business value: {}'.format(self._value))
self._value+=1awaitasyncio.sleep(1)
asyncdefsimulate_user_request():
awaitasyncio.sleep(5)
return"reset"if__name__=='__main__':
app=App()
loop=asyncio.get_event_loop()
loop.run_until_complete(app.serve())
loop.close()