网上演练
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

// Needed for Workaround
#if !NET_4_6
using System;
namespace LinqInternal.Threading.Needles
{
[Serializable]
[System.Diagnostics.DebuggerNonUserCode]
internal class ReadOnlyPromise : IWaitablePromise
{
private readonly IPromise _promised;
private readonly Action _wait;
public ReadOnlyPromise(IPromise promised, bool allowWait)
{
_promised = promised;
if (allowWait)
{
var promise = _promised as IWaitablePromise;
if (promise != null)
{
_wait = promise.Wait;
}
else
{
_wait = () => ThreadingHelper.SpinWaitUntil(() => _promised.IsCompleted);
}
}
else
{
_wait = () =>
{
throw new InvalidOperationException();
};
}
}
public Exception Exception
{
get { return _promised.Exception; }
}
public bool IsCanceled
{
get { return _promised.IsCanceled; }
}
public bool IsCompleted
{
get { return _promised.IsCompleted; }
}
public bool IsFaulted
{
get { return _promised.IsFaulted; }
}
public override int GetHashCode()
{
return _promised.GetHashCode();
}
public override string ToString()
{
return string.Format("{{Promise: {0}}}", _promised);
}
public void Wait()
{
_wait();
}
}
}
#endif