annotate Implab/PromiseActionReaction`1.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 fb70574741a1
children d82909310094
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
247
fb70574741a1 working on promises
cin
parents:
diff changeset
1 using System;
fb70574741a1 working on promises
cin
parents:
diff changeset
2 using System.Diagnostics;
fb70574741a1 working on promises
cin
parents:
diff changeset
3
fb70574741a1 working on promises
cin
parents:
diff changeset
4 namespace Implab {
fb70574741a1 working on promises
cin
parents:
diff changeset
5 class PromiseActionReaction<T> : PromiseReaction<T> {
fb70574741a1 working on promises
cin
parents:
diff changeset
6 readonly Deferred m_next;
fb70574741a1 working on promises
cin
parents:
diff changeset
7
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
8 public IPromise Promise {
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
9 get { return m_next.Promise; }
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
10 }
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
11
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
12 public PromiseActionReaction(Action<T> fulfilled, Action<Exception> rejected, IDispatcher dispatcher) : base(dispatcher) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
13 m_next = new Deferred(dispatcher);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
14 if (fulfilled != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
15 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
16
fb70574741a1 working on promises
cin
parents:
diff changeset
17 if (rejected != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
18 RejectHandler = PromiseHandler.Create(rejected, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
19 }
fb70574741a1 working on promises
cin
parents:
diff changeset
20
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
21 public PromiseActionReaction(Func<T, IPromise> fulfilled, Func<Exception, IPromise> rejected, IDispatcher dispatcher) : base(dispatcher) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
22 m_next = new Deferred(dispatcher);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
23 if (fulfilled != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
24 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
25
fb70574741a1 working on promises
cin
parents:
diff changeset
26 if (rejected != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
27 RejectHandler = PromiseHandler.Create(rejected, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
28 }
fb70574741a1 working on promises
cin
parents:
diff changeset
29
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
30 public PromiseActionReaction(Action<T> fulfilled, Func<Exception, IPromise> rejected, IDispatcher dispatcher) : base(dispatcher) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
31 m_next = new Deferred(dispatcher);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
32 if (fulfilled != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
33 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
34
fb70574741a1 working on promises
cin
parents:
diff changeset
35 if (rejected != null)
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
36 RejectHandler = PromiseHandler.Create(rejected, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
37 }
fb70574741a1 working on promises
cin
parents:
diff changeset
38
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
39 public PromiseActionReaction(Func<T, IPromise> fulfilled, Action<Exception> rejected, IDispatcher dispatcher) : base(dispatcher) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
40 m_next = new Deferred(dispatcher);
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
41 if (fulfilled != null)
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
42 FulfilHandler = PromiseHandler.Create(fulfilled, m_next);
247
fb70574741a1 working on promises
cin
parents:
diff changeset
43
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
44 if (rejected != null)
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
45 RejectHandler = PromiseHandler.Create(rejected, m_next);
5cb4826c2c2a Added awaiters to promises
cin
parents: 247
diff changeset
46 }
247
fb70574741a1 working on promises
cin
parents:
diff changeset
47
fb70574741a1 working on promises
cin
parents:
diff changeset
48 protected override void DefaultReject(Exception reason) {
fb70574741a1 working on promises
cin
parents:
diff changeset
49 m_next.Reject(reason);
fb70574741a1 working on promises
cin
parents:
diff changeset
50 }
fb70574741a1 working on promises
cin
parents:
diff changeset
51
fb70574741a1 working on promises
cin
parents:
diff changeset
52 protected override void DefaultResolve(T result) {
fb70574741a1 working on promises
cin
parents:
diff changeset
53 m_next.Resolve();
fb70574741a1 working on promises
cin
parents:
diff changeset
54 }
fb70574741a1 working on promises
cin
parents:
diff changeset
55 }
fb70574741a1 working on promises
cin
parents:
diff changeset
56 }