public async Task GetUpdateForOrder(Order order) { await Clients.Others.NewOrder(order); UpdateInfo result; do { result = _orderChecker.GetUpdate(order); await Task.Delay(700); if (!result.New) { continue; } await Clients.Caller.ReceiveOrderUpate(result); await Clients.Group("allUpdateReceivers").ReceiveOrderUpate(result); } while (!result.Finished); await Clients.Caller.Finished(order); }
// This method gets called by the client right after a new order has been placed public async Task GetUpdateForOrder(Order order) { // I first allowed other clients to know there is a new order, we use Clients property of the Hub base class // which gives access to the Clients object with this I can call function on clients await Clients.Others.NewOrder(order); UpdateInfo result; do { result = _orderChecker.GetUpdate(order); await Task.Delay(700); if (!result.New) { continue; } await Clients.Caller.ReceiveOrderUpdate(result); } while (!result.Finished); await Clients.Caller.Finished(order); }
private async Task SendEvents(WebSocket webSocket, int orderNo) { CheckResult result; do { result = _orderChecker.GetUpdate(orderNo); Thread.Sleep(2000); if (!result.New) { continue; } var jsonMessage = $"\"{result.Update}\""; await webSocket.SendAsync(buffer : new ArraySegment <byte>( array: Encoding.ASCII.GetBytes(jsonMessage), offset: 0, count: jsonMessage.Length), messageType : WebSocketMessageType.Text, endOfMessage : true, cancellationToken : CancellationToken.None); } while (!result.Finished); }