internal static Task<BufferedReadStream> BufferStreamAsync(Stream inputStream) { BufferedReadStream bufferedReadStream = new BufferedReadStream(inputStream); return Task.Factory.Iterate(bufferedReadStream.BufferInputStream()).FollowAlwaysWith(delegate (Task task) { inputStream.Dispose(); }).FollowOnSuccessWith<BufferedReadStream>(delegate (Task task) { bufferedReadStream.ResetForReading(); return bufferedReadStream; }); }
internal static Task <BufferedReadStream> BufferStreamAsync(Stream inputStream) { BufferedReadStream bufferedReadStream = new BufferedReadStream(inputStream); return(Task.Factory.Iterate(bufferedReadStream.BufferInputStream()).FollowAlwaysWith(delegate(Task task) { inputStream.Dispose(); }).FollowOnSuccessWith <BufferedReadStream>(delegate(Task task) { bufferedReadStream.ResetForReading(); return bufferedReadStream; })); }
/// <summary> /// Given the <paramref name="inputStream"/> this method returns a task which will asynchronously /// read the entire content of that stream and return a new synchronous stream from which the data can be read. /// </summary> /// <param name="inputStream">The input stream to asynchronously buffer.</param> /// <returns>A task which returns the buffered stream.</returns> internal static Task <BufferedReadStream> BufferStreamAsync(Stream inputStream) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(inputStream != null, "inputStream != null"); BufferedReadStream bufferedReadStream = new BufferedReadStream(inputStream); // Note that this relies on lazy eval of the enumerator return(Task.Factory.Iterate(bufferedReadStream.BufferInputStream()) .FollowAlwaysWith((task) => inputStream.Dispose()) .FollowOnSuccessWith( (task) => { bufferedReadStream.ResetForReading(); return bufferedReadStream; })); }