##// END OF EJS Templates
added promise timeout helper
cin -
r110:1a8426e6e895 v2
parent child
Show More
@@ -72,6 +72,23 namespace Implab {
72 72 }
73 73 };
74 74 }
75
76 static void CancelCallback(object cookie) {
77 ((ICancellable)cookie).Cancel();
78 }
79
80 /// <summary>
81 /// Cancells promise after the specified timeout is elapsed.
82 /// </summary>
83 /// <param name="that">The promise to cancel on timeout.</param>
84 /// <param name="milliseconds">The timeout in milliseconds.</param>
85 /// <typeparam name="TPromise">The 1st type parameter.</typeparam>
86 public static TPromise Timeout<TPromise>(this TPromise that, int milliseconds) where TPromise : IPromise {
87 Safe.ArgumentNotNull(that, "that");
88 var timer = new Timer(CancelCallback, that, milliseconds, -1);
89 that.On(timer.Dispose, PromiseEventType.All);
90 return that;
91 }
75 92
76 93 #if NET_4_5
77 94
General Comments 0
You need to be logged in to leave comments. Login now