Commit 5cfb1f27 authored by justcoding121's avatar justcoding121

use async await

parent af550aaf
...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Helpers
return writeAsyncInternal(value, false, cancellationToken); return writeAsyncInternal(value, false, cancellationToken);
} }
private Task writeAsyncInternal(string value, bool addNewLine, CancellationToken cancellationToken) private async Task writeAsyncInternal(string value, bool addNewLine, CancellationToken cancellationToken)
{ {
int newLineChars = addNewLine ? newLine.Length : 0; int newLineChars = addNewLine ? newLine.Length : 0;
int charCount = value.Length; int charCount = value.Length;
...@@ -67,15 +67,11 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -67,15 +67,11 @@ namespace Titanium.Web.Proxy.Helpers
idx += newLineChars; idx += newLineChars;
} }
return stream.WriteAsync(buffer, 0, idx, cancellationToken).ContinueWith((antecedent) => await stream.WriteAsync(buffer, 0, idx, cancellationToken);
{
bufferPool.ReturnBuffer(buffer);
});
} }
catch(Exception ex) finally
{ {
bufferPool.ReturnBuffer(buffer); bufferPool.ReturnBuffer(buffer);
throw ex;
} }
} }
else else
...@@ -91,7 +87,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -91,7 +87,7 @@ namespace Titanium.Web.Proxy.Helpers
idx += newLineChars; idx += newLineChars;
} }
return stream.WriteAsync(buffer, 0, idx, cancellationToken); await stream.WriteAsync(buffer, 0, idx, cancellationToken);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment