##// END OF EJS Templates
Added awaiters to promises...
Added awaiters to promises Added static methods to Promise Resolve, Reject, All. Updated promise helpers

File last commit:

r248:5cb4826c2c2a v3
r248:5cb4826c2c2a v3
Show More
PromiseReaction`1.cs
41 lines | 1.5 KiB | text/x-csharp | CSharpLexer
/ Implab / PromiseReaction`1.cs
cin
missing files
r246 using System;
namespace Implab {
cin
Added awaiters to promises...
r248 /// <summary>
/// Базовыйй класс для создания обработчиков результов выполнения обещаний.
/// Данный объект связывает обработчик и обешание, при этом для выполнения
/// обработчика будет использоваться диспетчер.
/// </summary>
cin
working on promises
r247 abstract class PromiseReaction<T> : IResolvable<T> {
readonly IDispatcher m_dispatcher;
protected PromiseReaction(IDispatcher dispatcher) {
m_dispatcher = dispatcher;
}
cin
missing files
r246
cin
Added awaiters to promises...
r248 protected Action<T> FulfilHandler { get; set; }
cin
missing files
r246
cin
Added awaiters to promises...
r248 protected Action<Exception> RejectHandler { get; set; }
cin
missing files
r246
public void Reject(Exception error) {
cin
Added awaiters to promises...
r248 if (RejectHandler == null)
cin
working on promises
r247 DefaultReject(error);
else if (m_dispatcher != null)
cin
Added awaiters to promises...
r248 m_dispatcher.Enqueue(RejectHandler, error);
cin
missing files
r246 else
cin
Added awaiters to promises...
r248 RejectHandler(error);
cin
missing files
r246 }
public void Resolve(T result) {
cin
Added awaiters to promises...
r248 if (FulfilHandler == null)
cin
working on promises
r247 DefaultResolve(result);
else if (m_dispatcher != null)
cin
Added awaiters to promises...
r248 m_dispatcher.Enqueue(FulfilHandler, result);
cin
missing files
r246 else
cin
Added awaiters to promises...
r248 FulfilHandler(result);
cin
missing files
r246 }
cin
working on promises
r247
protected abstract void DefaultResolve(T result);
protected abstract void DefaultReject(Exception reason);
cin
missing files
r246 }
}