Commit f16e145e authored by Nick Craver's avatar Nick Craver

Clenaup: ResultBox

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