public Task HandleEventsLoop() { isRunning = true; while (isRunning) { using ZFrame receivedFrame = socket.ReceiveFrame(); byte[] receivedRawData = receivedFrame.Read(); TEvent engineActionEvent = EventsSerializer.DeserializeEvent <TEvent>(receivedRawData); TResponseEvent response = onEventReceived(engineActionEvent); byte[] responseRawData = EventsSerializer.SerializeEvent <TResponseEvent>(response); socket.Send(new ZFrame(responseRawData)); } return(Task.CompletedTask); }
/// <summary> /// Sends an <see cref="TEvent"/> directly, this will not handle receiving events back! /// </summary> /// <param name="eventData"></param> public void SendEvent(TEvent eventData) { lock (requesterLock) { byte[] data = EventsSerializer.SerializeEvent <TEvent>(eventData); requester.Send(new ZFrame(data), out ZError error); if (error == null) { return; } if (!error.Equals(ZError.None)) { //Error } } }