comparison Implab/PromiseExtensions.cs @ 151:ec91a6dfa5b3 v2

Added support for 'await' operator to promises
author cin
date Thu, 04 Feb 2016 02:43:05 +0300
parents eb793fbbe4ea
children 822aab37b107
comparison
equal deleted inserted replaced
150:3258399cba83 151:ec91a6dfa5b3
285 #endregion 285 #endregion
286 286
287 287
288 #if NET_4_5 288 #if NET_4_5
289 289
290 public static Task<T> GetTask<T>(this IPromise<T> that) { 290 public static PromiseAwaiter<T> GetAwaiter<T>(this IPromise<T> that) {
291 Safe.ArgumentNotNull(that, "that"); 291 Safe.ArgumentNotNull(that, "that");
292 var tcs = new TaskCompletionSource<T>(); 292
293 293 return new PromiseAwaiter<T>(that);
294 that.On(tcs.SetResult, tcs.SetException, r => tcs.SetCanceled());
295
296 return tcs.Task;
297 } 294 }
298 295
299 #endif 296 #endif
300 } 297 }
301 } 298 }