##// END OF EJS Templates
fix MTQueue syntax error
fix MTQueue syntax error

File last commit:

r76:c761fc982e1d v2
r98:4c945d94b9ab v2
Show More
PromiseExtensions.cs
65 lines | 1.8 KiB | text/x-csharp | CSharpLexer
/ Implab / PromiseExtensions.cs
cin
promises refactoring
r72 using System.Threading;
cin
major refactoring, added tasks support
r75 using System;
#if NET_4_5
using System.Threading.Tasks;
#endif
cin
promises refactoring
r72
namespace Implab {
public static class PromiseExtensions {
public static IPromise<T> DispatchToCurrentContext<T>(this IPromise<T> that) {
cin
major refactoring, added tasks support
r75 Safe.ArgumentNotNull(that, "that");
cin
promises refactoring
r72 var context = SynchronizationContext.Current;
if (context == null)
return that;
var p = new SyncContextPromise<T>(context, that, true);
cin
Refactoring of the IPromise<T> interface...
r76 that.Last(
p.Resolve,
p.Reject,
p.Cancel
cin
promises refactoring
r72 );
return p;
}
public static IPromise<T> DispatchToContext<T>(this IPromise<T> that, SynchronizationContext context) {
cin
major refactoring, added tasks support
r75 Safe.ArgumentNotNull(that, "that");
cin
promises refactoring
r72 Safe.ArgumentNotNull(context, "context");
var p = new SyncContextPromise<T>(context, that, true);
cin
Refactoring of the IPromise<T> interface...
r76 that.Last(
p.Resolve,
p.Reject,
p.Cancel
cin
promises refactoring
r72 );
return p;
}
cin
major refactoring, added tasks support
r75
public static AsyncCallback AsyncCallback<T>(this Promise<T> that, Func<IAsyncResult,T> callback) {
Safe.ArgumentNotNull(that, "that");
Safe.ArgumentNotNull(callback, "callback");
return ar => {
try {
that.Resolve(callback(ar));
} catch (Exception err) {
that.Reject(err);
}
};
}
#if NET_4_5
public static Task<T> GetTask<T>(this IPromise<T> that) {
Safe.ArgumentNotNull(that, "that");
var tcs = new TaskCompletionSource<T>();
that.Last(tcs.SetResult, tcs.SetException, tcs.SetCanceled);
return tcs.Task;
}
#endif
cin
promises refactoring
r72 }
}