-
-
Save grumpydev/5236032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!this.stream.CanSeek) | |
{ | |
var tcs = new TaskCompletionSource<Stream>(); | |
var buffer = | |
new MemoryStream((int)this.stream.Length); | |
this.stream.CopyTo(buffer, (source, destination, ex) => | |
{ | |
if (ex != null) | |
{ | |
tcs.SetException(ex); | |
} | |
else | |
{ | |
tcs.SetResult(destination); | |
} | |
}); | |
var task = tcs.Task; | |
// ^^ pull this out into a method that returns tcs.task | |
task.Wait(); | |
if (task.IsFaulted) | |
{ | |
throw new InvalidOperationException("Unable to copy stream", task.Exception); | |
} | |
this.stream = task.Result. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment