Exemplo n.º 1
0
        public static DatastoreResults <T> WithEntries(DatastoreQuery <T> q, DatastoreEntry <T>[] res)
        {
            var b = new ResultBuilder(q);

            Task.Factory.StartNew(() =>
            {
                foreach (var r in res.Select(e => new DatastoreResult <T>(e)))
                {
                    b.Output.Add(r, b.Cancellation.Token);
                }
            }).ContinueWith(_ => b.Output.CompleteAdding());

            return(b.Results());
        }
Exemplo n.º 2
0
            public ResultBuilder(DatastoreQuery <T> q)
            {
                var bufSize = 1;

                if (q.KeysOnly)
                {
                    bufSize = DatastoreQuery <T> .KeysOnlyBufferSize;
                }

                DatastoreQuery = q;
                Output         = new BlockingCollection <DatastoreResult <T> >(bufSize);
                Cancellation   = new CancellationTokenSource();
                Cancellation.Token.Register(() => Output.CompleteAdding());
            }
Exemplo n.º 3
0
        public static DatastoreResults <T> WithCollection(DatastoreQuery <T> q, BlockingCollection <DatastoreResult <T> > res)
        {
            var b = new ResultBuilder(q);

            Task.Factory.StartNew(() =>
            {
                DatastoreResult <T> item;
                while (res.TryTake(out item, Timeout.Infinite, b.Cancellation.Token))
                {
                    b.Output.Add(item, b.Cancellation.Token);
                }
            }).ContinueWith(_ => b.Output.CompleteAdding());

            return(b.Results());
        }
Exemplo n.º 4
0
 internal DatastoreResults(DatastoreQuery <T> datastoreQuery, CancellationTokenSource cancellation, BlockingCollection <DatastoreResult <T> > res)
 {
     DatastoreQuery = datastoreQuery;
     Cancellation   = cancellation;
     _res           = res;
 }
Exemplo n.º 5
0
 public static DatastoreResults <T> ReplaceQuery(DatastoreResults <T> r, DatastoreQuery <T> q) => new DatastoreResults <T>(q, r.Cancellation, r.Next());