using System.Threading; using System; using Implab.Diagnostics; using System.Collections.Generic; using System.Linq; namespace Implab { public static class PromiseExtensions { public static IPromise Then(this IPromise that, Action fulfilled, Action rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Action fulfilled) { var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Action fulfilled, Func rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Action rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled) { var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Action fulfilled, Action rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Action fulfilled) { var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Action fulfilled, Func rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Action rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled) { var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func rejected) { var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled) { var reaction = PromiseFuncReaction.Create(fulfilled, (Func)null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func> rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled, Func rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled) { var reaction = PromiseFuncReaction.Create(fulfilled, (Func)null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled, Func> rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled) { var reaction = PromiseFuncReaction.Create(fulfilled, (Func)null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func fulfilled, Func> rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled, Func rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled) { var reaction = PromiseFuncReaction.Create(fulfilled, (Func)null, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Then(this IPromise that, Func> fulfilled, Func> rejected) { var reaction = PromiseFuncReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher); that.Then(reaction); return reaction.Promise; } public static IPromise Catch(this IPromise that, Action rejected) { return Then(that, null, rejected); } public static IPromise Catch(this IPromise that, Func rejected) { return Then(that, null, rejected); } public static IPromise Catch(this IPromise that, Func rejected) { return Then(that, (Func)null, rejected); } public static IPromise Catch(this IPromise that, Func> rejected) { return Then(that, (Func)null, rejected); } public static IPromise Catch(this IPromise that, Func rejected) { return Then(that, (Func)null, rejected); } public static IPromise Catch(this IPromise that, Func> rejected) { return Then(that, (Func)null, rejected); } public static IPromise Finally(this IPromise that, Action final) { return Then(that, final, e => { final(); throw e.Rethrow(); }); } public static IPromise Finally(this IPromise that, Func final) { return Then(that, final, e => { final(); throw e.Rethrow(); }); } public static IPromise Finally(this IPromise that, Action final) { return Then(that, x => { final(); return x; }, new Func(e => { final(); throw e.Rethrow(); })); } public static IPromise Finally(this IPromise that, Func final) { return Then(that, x => { return final() .Then(() => x); }, new Func>(e => { return final() .Then(new Func(() => { throw e.Rethrow(); })); })); } } }