PromiseReaction.cs
44 lines
| 1.1 KiB
| text/x-csharp
|
CSharpLexer
/ Implab / PromiseReaction.cs
cin
|
r246 | using System; | |
namespace Implab { | |||
cin
|
r247 | abstract class PromiseReaction : IResolvable { | |
readonly IDispatcher m_dispatcher; | |||
protected PromiseReaction(IDispatcher dispatcher) { | |||
m_dispatcher = dispatcher; | |||
} | |||
cin
|
r246 | ||
cin
|
r247 | protected abstract bool HasFulfilHandler { | |
get; | |||
} | |||
cin
|
r246 | ||
cin
|
r247 | protected abstract bool HasRejectHandler { | |
get; | |||
} | |||
cin
|
r246 | ||
public void Reject(Exception error) { | |||
cin
|
r247 | if (!HasRejectHandler) | |
DefaultReject(error); | |||
else if (m_dispatcher != null) | |||
m_dispatcher.Enqueue(() => RejectImpl(error)); | |||
else | |||
RejectImpl(error); | |||
cin
|
r246 | } | |
public void Resolve() { | |||
cin
|
r247 | if (!HasFulfilHandler) | |
DefaultResolve(); | |||
else if (m_dispatcher != null) | |||
m_dispatcher.Enqueue(ResolveImpl); | |||
else | |||
ResolveImpl(); | |||
cin
|
r246 | } | |
cin
|
r247 | ||
protected abstract void ResolveImpl(); | |||
protected abstract void RejectImpl(Exception reason); | |||
protected abstract void DefaultResolve(); | |||
protected abstract void DefaultReject(Exception reason); | |||
cin
|
r246 | } | |
} |