Commit f16e145e authored by Nick Craver's avatar Nick Craver

Clenaup: ResultBox

parent 94d20d5e
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
abstract partial class ResultBox internal abstract partial class ResultBox
{ {
protected Exception exception; protected Exception exception;
...@@ -32,12 +32,11 @@ protected static void IncrementAllocationCount() ...@@ -32,12 +32,11 @@ protected static void IncrementAllocationCount()
static partial void OnAllocated(); static partial void OnAllocated();
} }
sealed class ResultBox<T> : ResultBox
internal sealed class ResultBox<T> : ResultBox
{ {
private static readonly ResultBox<T>[] store = new ResultBox<T>[64]; private static readonly ResultBox<T>[] store = new ResultBox<T>[64];
private object stateOrCompletionSource; private object stateOrCompletionSource;
private T value; private T value;
public ResultBox(object stateOrCompletionSource) public ResultBox(object stateOrCompletionSource)
...@@ -96,18 +95,18 @@ public void SetResult(T value) ...@@ -96,18 +95,18 @@ public void SetResult(T value)
public override bool TryComplete(bool isAsync) public override bool TryComplete(bool isAsync)
{ {
if (stateOrCompletionSource is TaskCompletionSource<T>) if (stateOrCompletionSource is TaskCompletionSource<T> tcs)
{ {
var tcs = (TaskCompletionSource<T>)stateOrCompletionSource;
#if !PLAT_SAFE_CONTINUATIONS // we don't need to check in this scenario #if !PLAT_SAFE_CONTINUATIONS // we don't need to check in this scenario
if (isAsync || TaskSource.IsSyncSafe(tcs.Task)) if (isAsync || TaskSource.IsSyncSafe(tcs.Task))
#endif #endif
{ {
T val; UnwrapAndRecycle(this, true, out T val, out Exception ex);
Exception ex;
UnwrapAndRecycle(this, true, out val, out ex);
if (ex == null) tcs.TrySetResult(val); if (ex == null)
{
tcs.TrySetResult(val);
}
else else
{ {
if (ex is TaskCanceledException) tcs.TrySetCanceled(); if (ex is TaskCanceledException) tcs.TrySetCanceled();
...@@ -144,5 +143,4 @@ private void Reset(object stateOrCompletionSource) ...@@ -144,5 +143,4 @@ private void Reset(object stateOrCompletionSource)
this.stateOrCompletionSource = stateOrCompletionSource; this.stateOrCompletionSource = stateOrCompletionSource;
} }
} }
} }
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