247
|
1 using System;
|
|
2 using System.Diagnostics;
|
|
3
|
|
4 namespace Implab {
|
|
5 class PromiseFuncReaction<TRet> : PromiseReaction {
|
|
6 readonly Deferred<TRet> m_next;
|
|
7
|
248
|
8 public IPromise<TRet> Promise {
|
|
9 get { return m_next.Promise; }
|
|
10 }
|
|
11
|
|
12 public PromiseFuncReaction(Func<TRet> fulfilled, Func<Exception, TRet> rejected, IDispatcher dispatcher) : base(dispatcher) {
|
|
13 m_next = new Deferred<TRet>(dispatcher);
|
247
|
14 if (fulfilled != null)
|
248
|
15 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
|
247
|
16
|
|
17 if (rejected != null)
|
248
|
18 RejectHandler = PromiseHandler.Create(rejected, m_next);
|
247
|
19 }
|
|
20
|
248
|
21 public PromiseFuncReaction(Func<IPromise<TRet>> fulfilled, Func<Exception, IPromise<TRet>> rejected, IDispatcher dispatcher) : base(dispatcher) {
|
|
22 m_next = new Deferred<TRet>(dispatcher);
|
247
|
23 if (fulfilled != null)
|
248
|
24 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
|
|
25
|
247
|
26 if (rejected != null)
|
248
|
27 RejectHandler = PromiseHandler.Create(rejected, m_next);
|
247
|
28 }
|
|
29
|
248
|
30 public PromiseFuncReaction(Func<TRet> fulfilled, Func<Exception, IPromise<TRet>> rejected, IDispatcher dispatcher) : base(dispatcher) {
|
|
31 m_next = new Deferred<TRet>(dispatcher);
|
247
|
32 if (fulfilled != null)
|
248
|
33 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
|
|
34
|
247
|
35 if (rejected != null)
|
248
|
36 RejectHandler = PromiseHandler.Create(rejected, m_next);
|
247
|
37 }
|
|
38
|
248
|
39 public PromiseFuncReaction(Func<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);
|
247
|
43
|
248
|
44 if (rejected != null)
|
|
45 RejectHandler = PromiseHandler.Create(rejected, m_next);
|
|
46 }
|
247
|
47
|
|
48 protected override void DefaultReject(Exception reason) {
|
|
49 m_next.Reject(reason);
|
|
50 }
|
|
51
|
|
52 protected override void DefaultResolve() {
|
|
53 throw new NotImplementedException();
|
|
54 }
|
|
55 }
|
|
56 } |