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); }
internal Task DispatchEventsThread() { while (!cancellationToken.IsCancellationRequested) { if (EventQueueCount == 0) { continue; } //Dequeue and send the event KeyValuePair <TEvent, Action <TResponseEvent> > eventToSend = DeQueueEvent(); SendEvent(eventToSend.Key); //Wait to receive the event try { ZFrame frame; lock (requesterLock) { frame = requester.ReceiveFrame(); } //Should we bother to put in the effort in deserializing the event if (eventToSend.Value != null) { TResponseEvent responseEvent = EventsSerializer.DeserializeEvent <TResponseEvent>(frame.Read()); eventToSend.Value.Invoke(responseEvent); } frame.Dispose(); } catch (ZException) { } } return(Task.CompletedTask); }