private RemoteBulkInsertOperation GetBulkInsertOperation() { if (current == null) { return(current = CreateBulkInsertOperation(Task.FromResult(0))); } if (processedItemsInCurrentOperation < options.ChunkedBulkInsertOptions.MaxDocumentsPerChunk) { if (options.ChunkedBulkInsertOptions.MaxChunkVolumeInBytes <= 0 || currentChunkSize < options.ChunkedBulkInsertOptions.MaxChunkVolumeInBytes) { return(current); } } // if we haven't flushed the previous one yet, we will force // a disposal of both the previous one and the one before, to avoid // consuming a lot of memory, and to have _too_ much concurrency. if (previousTask != null) { previousTask.ConfigureAwait(false).GetAwaiter().GetResult(); } previousTask = current.DisposeAsync(); currentChunkSize = 0; processedItemsInCurrentOperation = 0; current = CreateBulkInsertOperation(previousTask); return(current); }
public async Task WaitForLastTaskToFinish() { if (disposed == false && current != null) { await current.DisposeAsync().ConfigureAwait(false); current = null; } }