Mercurial > pub > ImplabNet
comparison Implab/PromiseFuncReaction`2.cs @ 248:5cb4826c2c2a v3
Added awaiters to promises
Added static methods to Promise Resolve, Reject, All.
Updated promise helpers
author | cin |
---|---|
date | Tue, 30 Jan 2018 01:37:17 +0300 |
parents | |
children | d82909310094 |
comparison
equal
deleted
inserted
replaced
247:fb70574741a1 | 248:5cb4826c2c2a |
---|---|
1 using System; | |
2 using System.Diagnostics; | |
3 | |
4 namespace Implab { | |
5 class PromiseFuncReaction<TIn, TRet> : PromiseReaction<TIn> { | |
6 readonly Deferred<TRet> m_next; | |
7 | |
8 public IPromise<TRet> Promise { | |
9 get { return m_next.Promise; } | |
10 } | |
11 | |
12 public PromiseFuncReaction(Func<TIn, TRet> fulfilled, Func<Exception, TRet> rejected, IDispatcher dispatcher) : base(dispatcher) { | |
13 m_next = new Deferred<TRet>(dispatcher); | |
14 if (fulfilled != null) | |
15 FulfilHandler = PromiseHandler.Create(fulfilled, m_next); | |
16 | |
17 if (rejected != null) | |
18 RejectHandler = PromiseHandler.Create(rejected, m_next); | |
19 } | |
20 | |
21 public PromiseFuncReaction(Func<TIn, IPromise<TRet>> fulfilled, Func<Exception, IPromise<TRet>> rejected, IDispatcher dispatcher) : base(dispatcher) { | |
22 m_next = new Deferred<TRet>(dispatcher); | |
23 if (fulfilled != null) | |
24 FulfilHandler = PromiseHandler.Create(fulfilled, m_next); | |
25 | |
26 if (rejected != null) | |
27 RejectHandler = PromiseHandler.Create(rejected, m_next); | |
28 } | |
29 | |
30 public PromiseFuncReaction(Func<TIn, TRet> fulfilled, Func<Exception, IPromise<TRet>> rejected, IDispatcher dispatcher) : base(dispatcher) { | |
31 m_next = new Deferred<TRet>(dispatcher); | |
32 if (fulfilled != null) | |
33 FulfilHandler = PromiseHandler.Create(fulfilled, m_next); | |
34 | |
35 if (rejected != null) | |
36 RejectHandler = PromiseHandler.Create(rejected, m_next); | |
37 } | |
38 | |
39 public PromiseFuncReaction(Func<TIn, IPromise<TRet>> fulfilled, Func<Exception, TRet> rejected, IDispatcher dispatcher) : base(dispatcher) { | |
40 m_next = new Deferred<TRet>(dispatcher); | |
41 if (fulfilled != null) | |
42 FulfilHandler = PromiseHandler.Create(fulfilled, m_next); | |
43 | |
44 if (rejected != null) | |
45 RejectHandler = PromiseHandler.Create(rejected, m_next); | |
46 } | |
47 | |
48 protected override void DefaultReject(Exception reason) { | |
49 m_next.Reject(reason); | |
50 } | |
51 | |
52 protected override void DefaultResolve(TIn result) { | |
53 m_next.Resolve((TRet)(object)result); | |
54 } | |
55 } | |
56 } |