comparison Implab/Safe.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 bdfdba6b645b
children 7c7e9ad6fe4a
comparison
equal deleted inserted replaced
247:fb70574741a1 248:5cb4826c2c2a
110 [DebuggerStepThrough] 110 [DebuggerStepThrough]
111 public static IPromise<T> Run<T>(Func<T> action) { 111 public static IPromise<T> Run<T>(Func<T> action) {
112 ArgumentNotNull(action, "action"); 112 ArgumentNotNull(action, "action");
113 113
114 try { 114 try {
115 return Promise<T>.FromResult(action()); 115 return Promise.Resolve(action());
116 } catch (Exception err) { 116 } catch (Exception err) {
117 return Promise<T>.FromException(err); 117 return Promise.Reject<T>(err);
118 } 118 }
119 } 119 }
120 120
121 [DebuggerStepThrough] 121 [DebuggerStepThrough]
122 public static IPromise Run(Action action) { 122 public static IPromise Run(Action action) {
123 ArgumentNotNull(action, "action"); 123 ArgumentNotNull(action, "action");
124 124
125 try { 125 try {
126 action(); 126 action();
127 return Promise.Success; 127 return Promise.Resolve();
128 } catch (Exception err) { 128 } catch (Exception err) {
129 return new FailedPromise(err); 129 return Promise.Reject(err);
130 } 130 }
131 } 131 }
132 132
133 [DebuggerStepThrough] 133 [DebuggerStepThrough]
134 public static IPromise Run(Func<IPromise> action) { 134 public static IPromise Run(Func<IPromise> action) {
135 ArgumentNotNull(action, "action"); 135 ArgumentNotNull(action, "action");
136 136
137 try { 137 try {
138 return action() ?? new FailedPromise(new Exception("The action returned null")); 138 return action() ?? Promise.Reject(new Exception("The action returned null"));
139 } catch (Exception err) { 139 } catch (Exception err) {
140 return new FailedPromise(err); 140 return Promise.Reject(err);
141 } 141 }
142 } 142 }
143 143
144 public static void NoWait(IPromise promise) { 144 public static void NoWait(IPromise promise) {
145 } 145 }
147 [DebuggerStepThrough] 147 [DebuggerStepThrough]
148 public static IPromise<T> Run<T>(Func<IPromise<T>> action) { 148 public static IPromise<T> Run<T>(Func<IPromise<T>> action) {
149 ArgumentNotNull(action, "action"); 149 ArgumentNotNull(action, "action");
150 150
151 try { 151 try {
152 return action() ?? Promise<T>.FromException(new Exception("The action returned null")); 152 return action() ?? Promise.Reject<T>(new Exception("The action returned null"));
153 } catch (Exception err) { 153 } catch (Exception err) {
154 return Promise<T>.FromException(err); 154 return Promise.Reject<T>(err);
155 } 155 }
156 } 156 }
157 157
158 #if NET_4_5 158 #if NET_4_5
159 public static void NoWait(Task t) { 159 public static void NoWait(Task t) {