Beispiel #1
0
        /*public Task<IResultChunk> GetNextChunkAsync()
         * {
         *  return _downloadTasks.IsCompleted ? Task.FromResult<SFResultChunk>(null) : _downloadTasks.Take();
         * }*/

        public Task <IResultChunk> GetNextChunkAsync()
        {
            logger.InfoFmt("NextChunkToConsume: {0}, NextChunkToDownload: {1}",
                           nextChunkToConsumeIndex, nextChunkToDownloadIndex);
            if (nextChunkToConsumeIndex < chunkInfos.Count)
            {
                Task <IResultChunk> chunk = taskQueues[nextChunkToConsumeIndex % prefetchSlot];

                if (nextChunkToDownloadIndex < chunkInfos.Count && nextChunkToConsumeIndex > 0)
                {
                    SFReusableChunk reusableChunk = chunkDatas[nextChunkToDownloadIndex % prefetchSlot];
                    reusableChunk.Reset(chunkInfos[nextChunkToDownloadIndex], nextChunkToDownloadIndex);

                    taskQueues[nextChunkToDownloadIndex % prefetchSlot] = DownloadChunkAsync(new DownloadContextV3()
                    {
                        chunk             = reusableChunk,
                        qrmk              = this.qrmk,
                        chunkHeaders      = this.chunkHeaders,
                        cancellationToken = externalCancellationToken
                    });
                    nextChunkToDownloadIndex++;
                }

                nextChunkToConsumeIndex++;
                return(chunk);
            }
            else
            {
                return(Task.FromResult <IResultChunk>(null));
            }
        }