Пример #1
0
 private protected TResult Wait <TResult>(Task <TResult> pending, Message message)
 {
     if (!redis.TryWait(pending))
     {
         throw ExceptionFactory.Timeout(redis.multiplexer, null, message, server);
     }
     return(pending.Result);
 }
Пример #2
0
                public bool MoveNext()
                {
                    switch (state)
                    {
                    case State.Complete:
                        return(false);

                    case State.Initial:
                        ProcessReply(parent.GetNextPageSync(this, nextCursor));
                        pageIndex = parent.initialOffset - 1;     // will be incremented in a moment
                        state     = State.Running;
                        LoadNextPageAsync();
                        goto case State.Running;

                    case State.Running:
                        // are we working through the current buffer?
                        if (SimpleNext())
                        {
                            return(true);
                        }

                        // do we have an outstanding operation? wait for the background task to finish
                        while (pending != null)
                        {
                            if (parent.TryWait(pending))
                            {
                                ProcessReply(pending.Result);
                            }
                            else
                            {
                                throw ExceptionFactory.Timeout(parent.redis.multiplexer, null, pendingMessage, parent.server);
                            }

                            if (SimpleNext())
                            {
                                return(true);
                            }
                        }

                        // nothing outstanding? wait synchronously
                        while (nextCursor != 0)
                        {
                            ProcessReply(parent.GetNextPageSync(this, nextCursor));
                            if (SimpleNext())
                            {
                                return(true);
                            }
                        }

                        // we're exhausted
                        state = State.Complete;
                        return(false);

                    case State.Disposed:
                    default:
                        throw new ObjectDisposedException(GetType().Name);
                    }
                }