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