async def proc2_worker(): endpoint = Endpoint() await endpoint.start_serving(ConnectionConfig.from_name('e2')) await endpoint.connect_to_endpoints(ConnectionConfig.from_name('e1'), ) for i in range(3): print("Requesting") result = await endpoint.request(GetSomethingRequest()) print(f"Got answer: {result.payload}")
async def run_proc1(): endpoint = Endpoint() await endpoint.start_serving(ConnectionConfig.from_name('e1')) await endpoint.connect_to_endpoints(ConnectionConfig.from_name('e2'), ) print("subscribing") # Listen for `GetSomethingRequest`'s endpoint.subscribe( GetSomethingRequest, lambda event: # Send a response back to *only* who made that request endpoint.broadcast_nowait(DeliverSomethingResponse("Yay"), event.broadcast_config()))
async def proc2_worker(): endpoint = Endpoint() await endpoint.start_serving(ConnectionConfig.from_name('e2')) await endpoint.connect_to_endpoints(ConnectionConfig.from_name('e1')) asyncio.ensure_future(display_proc1_events(endpoint)) endpoint.subscribe( FirstThingHappened, lambda event: print( "Received via SUBSCRIBE API in proc2:", event.payload)) while True: print("Hello from proc2") if is_nth_second(2): await endpoint.broadcast( SecondThingHappened("Hit from proc2 ({})".format(time.time()))) await asyncio.sleep(1)