コード例 #1
0
 internal void Call(RespConnection connection, Lifetime <Memory <RespValue> > args, Action <RespValue>?inspector = null)
 {
     using (args)
     {
         Interlocked.Increment(ref _opCount);
         connection.Send(RespValue.CreateAggregate(RespType.Array, args.Value));
     }
     using var response = connection.Receive();
     response.Value.ThrowIfError();
     inspector?.Invoke(response.Value);
 }
コード例 #2
0
 internal T Call <T>(RespConnection connection, Lifetime <Memory <RespValue> > args, Func <RespValue, T> selector)
 {
     using (args)
     {
         Interlocked.Increment(ref _opCount);
         connection.Send(RespValue.CreateAggregate(RespType.Array, args.Value));
     }
     using var response = connection.Receive();
     response.Value.ThrowIfError();
     return(selector(response.Value));
 }
コード例 #3
0
        internal void Call(RespConnection connection, List <IBatchedOperation> operations)
        {
            try
            {
                int len = operations.Count;
                if (len == 0)
                {
                    return;
                }
                // push the fisrt *before* we context-switch; the rest can wait
                Send(this, connection, operations[0], true);
                Task?bgSend = len == 1 ? null : BeginSendRemainderInBackground(this, connection, operations, default);

                foreach (var op in operations) // then receive all
                {
                    using var response = connection.Receive();
                    try
                    {
                        response.Value.ThrowIfError();
                        op.ProcessResponse(response.Value);
                    }
                    catch (Exception ex)
                    {
                        op.TrySetException(ex);
                    }
                }
                if (bgSend != null)
                {
                    Wait(bgSend);
                }
            }
            catch (Exception ex)
            {
                connection.Doom();
                foreach (var op in operations) // fault anything that is left after a global explosion
                {
                    op.TrySetException(ex);
                }
            }
        }