@@ -73,6 +73,23 namespace Implab { | |||
|
73 | 73 | }; |
|
74 | 74 | } |
|
75 | 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 | } | |
|
92 | ||
|
76 | 93 | #if NET_4_5 |
|
77 | 94 | |
|
78 | 95 | public static Task<T> GetTask<T>(this IPromise<T> that) { |
General Comments 0
You need to be logged in to leave comments.
Login now