comparison Implab/FailedPromiseT.cs @ 203:4d9830a9bbb8 v2

Added 'Fail' method to RunnableComponent which allows component to move from Running to Failed state. Added PollingComponent a timer based runnable component More tests Added FailPromise a thin class to wrap exceptions Fixed error handling in SuccessPromise classes.
author cin
date Tue, 18 Oct 2016 17:49:54 +0300
parents
children cbe10ac0731e
comparison
equal deleted inserted replaced
202:2651cb9a4250 203:4d9830a9bbb8
1 using System;
2 using System.Reflection;
3
4 namespace Implab {
5 public class FailedPromise<T> : FailedPromise, IPromise<T> {
6 public FailedPromise(Exception error) : base(error) {
7 }
8
9 public IPromise<T> On(Action<T> success, Action<Exception> error, Action<Exception> cancel) {
10 if (error != null) {
11 try {
12 error(Error);
13 // Analysis disable once EmptyGeneralCatchClause
14 } catch {
15 }
16 }
17 return this;
18 }
19
20 public IPromise<T> On(Action<T> success, Action<Exception> error) {
21 if (error != null) {
22 try {
23 error(Error);
24 // Analysis disable once EmptyGeneralCatchClause
25 } catch {
26 }
27 }
28 return this;
29 }
30
31 public IPromise<T> On(Action<T> success) {
32 return this;
33 }
34
35 T IPromise<T>.Join() {
36 throw new TargetInvocationException(Error);
37 }
38
39 T IPromise<T>.Join(int timeout) {
40 throw new TargetInvocationException(Error);
41 }
42
43
44 IPromise<T> IPromise<T>.On(Action success, Action<Exception> error, Action<Exception> cancel) {
45 On(success, error, cancel);
46 return this;
47 }
48
49 IPromise<T> IPromise<T>.On(Action success, Action<Exception> error) {
50 On(success, error);
51 return this;
52 }
53
54 IPromise<T> IPromise<T>.On(Action success) {
55 On(success);
56 return this;
57 }
58
59 IPromise<T> IPromise<T>.On(Action handler, PromiseEventType events) {
60 On(handler, events);
61 return this;
62 }
63 }
64 }
65