Пример #1
0
 private void Cache_OnItems(ICollection <CacheValue> items)
 {
     _lock.EnterReadLock();
     try
     {
         foreach (var client in _clients)
         {
             client.Post(ResponseMessageModel.Create(items));
         }
     }
     finally { _lock.ExitReadLock(); }
 }
Пример #2
0
        private static async Task Receive(IInteract context, IServerCache cache, BufferBlock <ResponseMessageModel> messages, CancellationToken token)
        {
            var it = context.Receive();
            EnumeratorResult <ChunkedStream> messageStream;

            while ((messageStream = await it.MoveNextAsync(token)).Success)
            {
                using (messageStream.Value)
                {
                    var message = ProtoBuf.Serializer.Deserialize <RequestMessageModel>(messageStream.Value);
                    var items   = cache.TryGetItems(message.Keys);
                    if (items.Count > 0)
                    {
                        var mes = ResponseMessageModel.Create(items);
                        if (!messages.Post(mes) && messages.TryReceive(out var last))
                        {
                            messages.Post(mes);
                        }
                    }
                }
            }
        }