diff --git a/Nuget.config b/Nuget.config new file mode 100644 index 0000000..fc8ccde --- /dev/null +++ b/Nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tests/A+ Spec/2.2.cs b/Tests/A+ Spec/2.2.cs index cf95514..c57e506 100644 --- a/Tests/A+ Spec/2.2.cs +++ b/Tests/A+ Spec/2.2.cs @@ -348,7 +348,7 @@ public void _when_promise1_is_rejected_with_no_value_in_catch() new Promise((res, rej) => rej(new Exception())) .Catch(_ => {}) - .Then(() => callbackInvoked = true); + .Then((x) => callbackInvoked = true); Assert.True(callbackInvoked); } diff --git a/src/Promise.cs b/src/Promise.cs index 7647358..bb1b0c0 100644 --- a/src/Promise.cs +++ b/src/Promise.cs @@ -10,41 +10,31 @@ namespace RSG /// Implements a C# promise. /// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise /// - public interface IPromise + public interface IPromise : IPromiseBase { - /// - /// Gets the id of the promise, useful for referencing the promise during runtime. - /// - int Id { get; } - /// /// Set the name of the promise, useful for debugging. /// - IPromise WithName(string name); + new IPromise WithName(string name); /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// onRejected is called on error. /// void Done(Action onResolved, Action onRejected); /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// Adds a default error handler. /// void Done(Action onResolved); /// - /// Complete the promise. Adds a default error handler. - /// - void Done(); - - /// - /// Handle errors for the promise. + /// Handle errors for the promise. /// - IPromise Catch(Action onRejected); + new IPromise Catch(Action onRejected); /// /// Handle errors for the promise. @@ -173,17 +163,6 @@ Action onProgress IPromise Progress(Action onProgress); } - /// - /// Interface for a promise that can be rejected. - /// - public interface IRejectable - { - /// - /// Reject the promise with an exception. - /// - void Reject(Exception ex); - } - /// /// Interface for a promise that can be rejected or resolved. /// @@ -205,37 +184,17 @@ public interface IPendingPromise : IRejectable void ReportProgress(float progress); } - /// - /// Specifies the state of a promise. - /// - public enum PromiseState - { - Pending, // The promise is in-flight. - Rejected, // The promise has been rejected. - Resolved // The promise has been resolved. - }; - /// /// Implements a C# promise. /// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise /// - public class Promise : IPromise, IPendingPromise, IPromiseInfo + public class Promise : Promise_Base, IPromise, IPendingPromise { - /// - /// The exception when the promise is rejected. - /// - private Exception rejectionException; - /// /// The value when the promises is resolved. /// private PromisedT resolveValue; - /// - /// Error handler. - /// - private List rejectHandlers; - /// /// Progress handlers. /// @@ -247,44 +206,11 @@ public class Promise : IPromise, IPendingPromise> resolveCallbacks; private List resolveRejectables; - /// - /// ID of the promise, useful for debugging. - /// - public int Id { get { return id; } } - - private readonly int id; - - /// - /// Name of the promise, when set, useful for debugging. - /// - public string Name { get; private set; } - - /// - /// Tracks the current state of the promise. - /// - public PromiseState CurState { get; private set; } - - public Promise() - { - this.CurState = PromiseState.Pending; - this.id = Promise.NextId(); - - if (Promise.EnablePromiseTracking) - { - Promise.PendingPromises.Add(this); - } - } + public Promise() : base() + { } - public Promise(Action, Action> resolver) + public Promise(Action, Action> resolver) : this() { - this.CurState = PromiseState.Pending; - this.id = Promise.NextId(); - - if (Promise.EnablePromiseTracking) - { - Promise.PendingPromises.Add(this); - } - try { resolver(Resolve, Reject); @@ -340,50 +266,17 @@ private void AddProgressHandler(Action onProgress, IRejectable rejectable progressHandlers.Add(new ProgressHandler { callback = onProgress, rejectable = rejectable }); } - /// - /// Invoke a single handler. - /// - private void InvokeHandler(Action callback, IRejectable rejectable, T value) - { -// Argument.NotNull(() => callback); -// Argument.NotNull(() => rejectable); - - try - { - callback(value); - } - catch (Exception ex) - { - rejectable.Reject(ex); - } - } - /// /// Helper function clear out all handlers after resolution or rejection. /// - private void ClearHandlers() + protected override void ClearHandlers() { - rejectHandlers = null; + base.ClearHandlers(); resolveCallbacks = null; resolveRejectables = null; progressHandlers = null; } - /// - /// Invoke all reject handlers. - /// - private void InvokeRejectHandlers(Exception ex) - { -// Argument.NotNull(() => ex); - - if (rejectHandlers != null) - { - rejectHandlers.Each(handler => InvokeHandler(handler.callback, handler.rejectable, ex)); - } - - ClearHandlers(); - } - /// /// Invoke all resolve handlers. /// @@ -398,8 +291,6 @@ private void InvokeResolveHandlers(PromisedT value) ClearHandlers(); } - - /// /// Invoke all progress handlers. /// private void InvokeProgressHandlers(float progress) @@ -411,31 +302,6 @@ private void InvokeProgressHandlers(float progress) } /// - /// Reject the promise with an exception. - /// - public void Reject(Exception ex) - { -// Argument.NotNull(() => ex); - - if (CurState != PromiseState.Pending) - { - throw new PromiseStateException( - "Attempt to reject a promise that is already in state: " + CurState - + ", a promise can only be rejected when it is still in state: " - + PromiseState.Pending - ); - } - - rejectionException = ex; - CurState = PromiseState.Rejected; - - if (Promise.EnablePromiseTracking) - { - Promise.PendingPromises.Remove(this); - } - - InvokeRejectHandlers(ex); - } /// /// Resolve the promise with a particular value. @@ -480,7 +346,7 @@ public void ReportProgress(float progress) } /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// onRejected is called on error. /// @@ -493,7 +359,7 @@ public void Done(Action onResolved, Action onRejected) } /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// Adds a default error handler. /// @@ -505,6 +371,32 @@ public void Done(Action onResolved) ); } + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// onRejected is called on error. + /// + void IPromiseBase.Done(Action onResolved, Action onRejected) + { + Then((x) => { onResolved(new PromiseResult(x)); }, onRejected) + .Catch(ex => + Promise.PropagateUnhandledException(this, ex) + ); + } + + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// Adds a default error handler. + /// + void IPromiseBase.Done(Action onResolved) + { + Then((x) => { onResolved(new PromiseResult(x)); }) + .Catch(ex => + Promise.PropagateUnhandledException(this, ex) + ); + } + /// /// Complete the promise. Adds a default error handler. /// @@ -525,21 +417,29 @@ public IPromise WithName(string name) } /// - /// Handle errors for the promise. + /// Set the name of the promise, useful for debugging. /// - public IPromise Catch(Action onRejected) + IPromiseBase IPromiseBase.WithName(string name) { - var resultPromise = new Promise(); + return WithName(name); + } + + /// + /// Handle errors for the promise. + /// + public IPromise Catch(Action onRejected) + { + var resultPromise = new Promise(); resultPromise.WithName(Name); - Action resolveHandler = _ => resultPromise.Resolve(); + Action resolveHandler = _ => resultPromise.Resolve(default(PromisedT)); Action rejectHandler = ex => { try { onRejected(ex); - resultPromise.Resolve(); + resultPromise.Resolve(default(PromisedT)); } catch(Exception cbEx) { @@ -581,6 +481,14 @@ public IPromise Catch(Func onRejected) return resultPromise; } + /// + /// Handle errors for the promise. + /// + IPromiseBase IPromiseBase.Catch(Action onRejected) + { + return Catch(onRejected); + } + /// /// Add a resolved callback that chains a value promise (optionally converting to a different value type). /// @@ -597,6 +505,14 @@ public IPromise Then(Func onResolved) return Then(onResolved, null, null); } + /// + /// Add a resolved callback that chains a non-value promise. + /// + IPromiseBase IPromiseBase.Then(Func onResolved) + { + return Then((x) => { onResolved(new PromiseResult(x)); }, null); + } + /// /// Add a resolved callback. /// @@ -605,6 +521,14 @@ public IPromise Then(Action onResolved) return Then(onResolved, null, null); } + /// + /// Add a resolved callback. + /// + IPromiseBase IPromiseBase.Then(Action onResolved) + { + return Then((x) => { onResolved(new PromiseResult(x)); }, null); + } + /// /// Add a resolved callback and a rejected callback. /// The resolved callback chains a value promise (optionally converting to a different value type). @@ -647,7 +571,7 @@ Action onProgress { // This version of the function must supply an onResolved. // Otherwise there is now way to get the converted value to pass to the resulting promise. -// Argument.NotNull(() => onResolved); +// Argument.NotNull(() => onResolved); var resultPromise = new Promise(); resultPromise.WithName(Name); @@ -741,6 +665,15 @@ public IPromise Then(Func onResolved, Action onR /// /// Add a resolved callback, a rejected callback and a progress callback. + /// The resolved callback chains a non-value promise. + /// + IPromiseBase IPromiseBase.Then(Func onResolved, Action onRejected) + { + return Then((x) => { onResolved(new PromiseResult(x)); }, onRejected); + } + + /// + /// Add a resolved callback and a rejected callback. /// public IPromise Then(Action onResolved, Action onRejected, Action onProgress) { @@ -776,6 +709,14 @@ public IPromise Then(Action onResolved, Action onRejected, return resultPromise; } + /// + /// Add a resolved callback and a rejected callback. + /// + IPromiseBase IPromiseBase.Then(Action onResolved, Action onRejected) + { + return Then((x) => { onResolved(new PromiseResult(x)); }, onRejected); + } + /// /// Return a new promise with a different value. /// May also change the type of the value. @@ -839,6 +780,17 @@ public IPromise ThenAll(Func> chain) return Then(value => Promise.All(chain(value))); } + /// + /// Chain an enumerable of promises, all of which must resolve. + /// Converts to a non-value promise. + /// The resulting promise is resolved when all of the promises have resolved. + /// It is rejected as soon as any of the promises have been rejected. + /// + IPromiseBase IPromiseBase.ThenAll(Func> chain) + { + return ThenAll((x) => { return chain(); }); + } + /// /// Returns a promise that resolves when all of the promises in the enumerable argument have resolved. /// Returns a promise of a collection of the resolved results. diff --git a/src/Promise_Base.cs b/src/Promise_Base.cs new file mode 100644 index 0000000..1cbb33a --- /dev/null +++ b/src/Promise_Base.cs @@ -0,0 +1,305 @@ +using System; +using System.Collections.Generic; +using RSG.Exceptions; +using RSG.Promises; + +namespace RSG +{ + public interface IPromiseBase + { + /// + /// ID of the promise, useful for debugging. + /// + int Id { get; } + + /// + /// Set the name of the promise, useful for debugging. + /// + IPromiseBase WithName(string name); + + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// onRejected is called on error. + /// + void Done(Action onResolved, Action onRejected); + + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// Adds a default error handler. + /// + void Done(Action onResolved); + + /// + /// Complete the promise. Adds a default error handler. + /// + void Done(); + + /// + /// Handle errors for the promise. + /// + IPromiseBase Catch(Action onRejected); + + /// + /// Add a resolved callback that chains a non-value promise. + /// + IPromiseBase Then(Func onResolved); + + /// + /// Add a resolved callback. + /// + IPromiseBase Then(Action onResolved); + + /// + /// Add a resolved callback and a rejected callback. + /// The resolved callback chains a non-value promise. + /// + IPromiseBase Then(Func onResolved, Action onRejected); + + /// + /// Add a resolved callback and a rejected callback. + /// + IPromiseBase Then(Action onResolved, Action onRejected); + + /// + /// Chain an enumerable of promises, all of which must resolve. + /// The resulting promise is resolved when all of the promises have resolved. + /// It is rejected as soon as any of the promises have been rejected. + /// + IPromiseBase ThenAll(Func> chain); + } + + /// + /// Interface for a promise that can be rejected. + /// + public interface IRejectable + { + /// + /// Reject the promise with an exception. + /// + void Reject(Exception ex); + } + + /// + /// Arguments to the UnhandledError event. + /// + public class ExceptionEventArgs : EventArgs + { + internal ExceptionEventArgs(Exception exception) + { + // Argument.NotNull(() => exception); + + this.Exception = exception; + } + + public Exception Exception + { + get; + private set; + } + } + + /// + /// Represents a handler invoked when the promise is rejected. + /// + public struct RejectHandler + { + /// + /// Callback fn. + /// + public Action callback; + + /// + /// The promise that is rejected when there is an error while invoking the handler. + /// + public IRejectable rejectable; + } + + /// + /// Option type for generic access to promised data + /// + public struct PromiseResult + { + public static readonly PromiseResult None = new PromiseResult(); + + public readonly bool hasValue; + public readonly object result; + + public PromiseResult(object value) + { + hasValue = true; + result = value; + } + } + + /// + /// Specifies the state of a promise. + /// + public enum PromiseState + { + Pending, // The promise is in-flight. + Rejected, // The promise has been rejected. + Resolved // The promise has been resolved. + }; + + /// + /// Used to list information of pending promises. + /// + public interface IPromiseInfo + { + /// + /// Id of the promise. + /// + int Id { get; } + + /// + /// Human-readable name for the promise. + /// + string Name { get; } + } + + public struct ProgressHandler + { + /// + /// Callback fn. + /// + public Action callback; + + /// + /// The promise that is rejected when there is an error while invoking the handler. + /// + public IRejectable rejectable; + } + + + public abstract class Promise_Base : IPromiseInfo + { + /// + /// Id for the next promise that is created. + /// + private static int nextPromiseId = 0; + + /// + /// The exception when the promise is rejected. + /// + protected Exception rejectionException; + + /// + /// Error handlers. + /// + protected List rejectHandlers; + + /// + /// ID of the promise, useful for debugging. + /// + public int Id { get; } + + /// + /// Name of the promise, when set, useful for debugging. + /// + public string Name { get; protected set; } + + /// + /// Tracks the current state of the promise. + /// + public PromiseState CurState { get; protected set; } + + public Promise_Base() + { + this.CurState = PromiseState.Pending; + this.Id = NextId(); + + if (Promise.EnablePromiseTracking) + { + Promise.PendingPromises.Add(this); + } + } + + /// + /// Increments the ID counter and gives us the ID for the next promise. + /// + internal static int NextId() + { + return ++nextPromiseId; + } + + /// + /// Add a rejection handler for this promise. + /// + protected void AddRejectHandler(Action onRejected, IRejectable rejectable) + { + if (rejectHandlers == null) + { + rejectHandlers = new List(); + } + + rejectHandlers.Add(new RejectHandler() + { + callback = onRejected, + rejectable = rejectable + }); + } + + /// + /// Invoke a single handler. + /// + protected void InvokeHandler(Action callback, IRejectable rejectable, T value) + { + // Argument.NotNull(() => callback); + // Argument.NotNull(() => rejectable); + + try + { + callback(value); + } + catch (Exception ex) + { + rejectable.Reject(ex); + } + } + + protected virtual void ClearHandlers() + { + rejectHandlers = null; + } + + /// + /// Invoke all reject handlers. + /// + protected void InvokeRejectHandlers(Exception ex) + { + // Argument.NotNull(() => ex); + + if (rejectHandlers != null) + { + rejectHandlers.Each(handler => InvokeHandler(handler.callback, handler.rejectable, ex)); + } + + ClearHandlers(); + } + + /// + /// Reject the promise with an exception. + /// + public void Reject(Exception ex) + { + // Argument.NotNull(() => ex); + + if (CurState != PromiseState.Pending) + { + throw new PromiseStateException("Attempt to reject a promise that is already in state: " + CurState + ", a promise can only be rejected when it is still in state: " + PromiseState.Pending); + } + + rejectionException = ex; + CurState = PromiseState.Rejected; + + if (Promise.EnablePromiseTracking) + { + Promise.PendingPromises.Remove(this); + } + + InvokeRejectHandlers(ex); + } + } +} diff --git a/src/Promise_NonGeneric.cs b/src/Promise_NonGeneric.cs index ae76308..2008d5e 100644 --- a/src/Promise_NonGeneric.cs +++ b/src/Promise_NonGeneric.cs @@ -1,4 +1,4 @@ -using RSG.Promises; +using RSG.Promises; using System; using System.Collections.Generic; using System.Linq; @@ -10,41 +10,31 @@ namespace RSG /// Implements a non-generic C# promise, this is a promise that simply resolves without delivering a value. /// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise /// - public interface IPromise + public interface IPromise : IPromiseBase { - /// - /// ID of the promise, useful for debugging. - /// - int Id { get; } - /// /// Set the name of the promise, useful for debugging. /// - IPromise WithName(string name); + new IPromise WithName(string name); /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// onRejected is called on error. /// void Done(Action onResolved, Action onRejected); /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// Adds a default error handler. /// void Done(Action onResolved); /// - /// Complete the promise. Adds a default error handler. - /// - void Done(); - - /// - /// Handle errors for the promise. + /// Handle errors for the promise. /// - IPromise Catch(Action onRejected); + new IPromise Catch(Action onRejected); /// /// Add a resolved callback that chains a value promise (optionally converting to a different value type). @@ -100,7 +90,7 @@ public interface IPromise /// The resulting promise is resolved when all of the promises have resolved. /// It is rejected as soon as any of the promises have been rejected. /// - IPromise ThenAll(Func> chain); + new IPromise ThenAll(Func> chain); /// /// Chain an enumerable of promises, all of which must resolve. @@ -181,75 +171,11 @@ public interface IPendingPromise : IRejectable void ReportProgress(float progress); } - /// - /// Used to list information of pending promises. - /// - public interface IPromiseInfo - { - /// - /// Id of the promise. - /// - int Id { get; } - - /// - /// Human-readable name for the promise. - /// - string Name { get; } - } - - /// - /// Arguments to the UnhandledError event. - /// - public class ExceptionEventArgs : EventArgs - { - internal ExceptionEventArgs(Exception exception) - { -// Argument.NotNull(() => exception); - - this.Exception = exception; - } - - public Exception Exception - { - get; - private set; - } - } - - /// - /// Represents a handler invoked when the promise is rejected. - /// - public struct RejectHandler - { - /// - /// Callback fn. - /// - public Action callback; - - /// - /// The promise that is rejected when there is an error while invoking the handler. - /// - public IRejectable rejectable; - } - - public struct ProgressHandler - { - /// - /// Callback fn. - /// - public Action callback; - - /// - /// The promise that is rejected when there is an error while invoking the handler. - /// - public IRejectable rejectable; - } - /// /// Implements a non-generic C# promise, this is a promise that simply resolves without delivering a value. /// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise /// - public class Promise : IPromise, IPendingPromise, IPromiseInfo + public class Promise : Promise_Base, IPromise, IPendingPromise { /// /// Set to true to enable tracking of promises. @@ -267,11 +193,6 @@ public static event EventHandler UnhandledException } private static EventHandler unhandlerException; - /// - /// Id for the next promise that is created. - /// - private static int nextPromiseId; - /// /// Information about pending promises. /// @@ -287,16 +208,6 @@ public static IEnumerable GetPendingPromises() return PendingPromises; } - /// - /// The exception when the promise is rejected. - /// - private Exception rejectionException; - - /// - /// Error handlers. - /// - private List rejectHandlers; - /// /// Represents a handler invoked when the promise is resolved. /// @@ -318,47 +229,16 @@ public struct ResolveHandler /// private List resolveHandlers; - /// /// Progress handlers. /// private List progressHandlers; /// - /// ID of the promise, useful for debugging. - /// - public int Id { get { return id; } } - - private readonly int id; - - /// - /// Name of the promise, when set, useful for debugging. - /// - public string Name { get; private set; } - - /// - /// Tracks the current state of the promise. - /// - public PromiseState CurState { get; private set; } + public Promise() : base() + { } - public Promise() + public Promise(Action> resolver) : this() { - this.CurState = PromiseState.Pending; - this.id = NextId(); - if (EnablePromiseTracking) - { - PendingPromises.Add(this); - } - } - - public Promise(Action> resolver) - { - this.CurState = PromiseState.Pending; - this.id = NextId(); - if (EnablePromiseTracking) - { - PendingPromises.Add(this); - } - try { resolver(Resolve, Reject); @@ -369,31 +249,6 @@ public Promise(Action> resolver) } } - /// - /// Increments the ID counter and gives us the ID for the next promise. - /// - internal static int NextId() - { - return ++nextPromiseId; - } - - /// - /// Add a rejection handler for this promise. - /// - private void AddRejectHandler(Action onRejected, IRejectable rejectable) - { - if (rejectHandlers == null) - { - rejectHandlers = new List(); - } - - rejectHandlers.Add(new RejectHandler - { - callback = onRejected, - rejectable = rejectable - }); - } - /// /// Add a resolve handler for this promise. /// @@ -481,28 +336,13 @@ private void InvokeProgressHandler(Action callback, IRejectable rejectabl /// /// Helper function clear out all handlers after resolution or rejection. /// - private void ClearHandlers() + override protected void ClearHandlers() { - rejectHandlers = null; + base.ClearHandlers(); resolveHandlers = null; progressHandlers = null; } - /// - /// Invoke all reject handlers. - /// - private void InvokeRejectHandlers(Exception ex) - { -// Argument.NotNull(() => ex); - - if (rejectHandlers != null) - { - rejectHandlers.Each(handler => InvokeRejectHandler(handler.callback, handler.rejectable, ex)); - } - - ClearHandlers(); - } - /// /// Invoke all resolve handlers. /// @@ -515,8 +355,6 @@ private void InvokeResolveHandlers() ClearHandlers(); } - - /// /// Invoke all progress handlers. /// private void InvokeProgressHandlers(float progress) @@ -528,32 +366,6 @@ private void InvokeProgressHandlers(float progress) } /// - /// Reject the promise with an exception. - /// - public void Reject(Exception ex) - { -// Argument.NotNull(() => ex); - - if (CurState != PromiseState.Pending) - { - throw new PromiseStateException( - "Attempt to reject a promise that is already in state: " + CurState - + ", a promise can only be rejected when it is still in state: " - + PromiseState.Pending - ); - } - - rejectionException = ex; - CurState = PromiseState.Rejected; - - if (EnablePromiseTracking) - { - PendingPromises.Remove(this); - } - - InvokeRejectHandlers(ex); - } - /// /// Resolve the promise with a particular value. @@ -599,7 +411,7 @@ public void ReportProgress(float progress) /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// onRejected is called on error. /// @@ -612,18 +424,44 @@ public void Done(Action onResolved, Action onRejected) } /// - /// Completes the promise. + /// Completes the promise. /// onResolved is called on successful completion. /// Adds a default error handler. /// public void Done(Action onResolved) { Then(onResolved) - .Catch(ex => + .Catch(ex => PropagateUnhandledException(this, ex) ); } + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// onRejected is called on error. + /// + void IPromiseBase.Done(Action onResolved, Action onRejected) + { + Then(() => { onResolved(PromiseResult.None); }, onRejected) + .Catch(ex => + Promise.PropagateUnhandledException(this, ex) + ); + } + + /// + /// Completes the promise. + /// onResolved is called on successful completion. + /// Adds a default error handler. + /// + void IPromiseBase.Done(Action onResolved) + { + Then(() => { onResolved(PromiseResult.None); }) + .Catch(ex => + Promise.PropagateUnhandledException(this, ex) + ); + } + /// /// Complete the promise. Adds a defualt error handler. /// @@ -642,7 +480,15 @@ public IPromise WithName(string name) } /// - /// Handle errors for the promise. + /// Set the name of the promise, useful for debugging. + /// + IPromiseBase IPromiseBase.WithName(string name) + { + return WithName(name); + } + + /// + /// Handle errors for the promise. /// public IPromise Catch(Action onRejected) { @@ -672,6 +518,14 @@ public IPromise Catch(Action onRejected) return resultPromise; } + /// + /// Handle errors for the promise. + /// + IPromiseBase IPromiseBase.Catch(Action onRejected) + { + return Catch(onRejected); + } + /// /// Add a resolved callback that chains a value promise (optionally converting to a different value type). /// @@ -688,6 +542,14 @@ public IPromise Then(Func onResolved) return Then(onResolved, null, null); } + /// + /// Add a resolved callback that chains a non-value promise. + /// + IPromiseBase IPromiseBase.Then(Func onResolved) + { + return Then(() => { onResolved(PromiseResult.None); }); + } + /// /// Add a resolved callback. /// @@ -696,6 +558,14 @@ public IPromise Then(Action onResolved) return Then(onResolved, null, null); } + /// + /// Add a resolved callback. + /// + IPromiseBase IPromiseBase.Then(Action onResolved) + { + return Then(() => { onResolved(PromiseResult.None); }); + } + /// /// Add a resolved callback and a rejected callback. /// The resolved callback chains a value promise (optionally converting to a different value type). @@ -827,6 +697,15 @@ public IPromise Then(Func onResolved, Action onRejected, Ac /// /// Add a resolved callback, a rejected callback and a progress callback. + /// The resolved callback chains a non-value promise. + /// + IPromiseBase IPromiseBase.Then(Func onResolved, Action onRejected) + { + return Then(() => { onResolved(PromiseResult.None); }, onRejected); + } + + /// + /// Add a resolved callback and a rejected callback. /// public IPromise Then(Action onResolved, Action onRejected, Action onProgress) { @@ -864,6 +743,14 @@ public IPromise Then(Action onResolved, Action onRejected, Action + /// Add a resolved callback and a rejected callback. + /// + IPromiseBase IPromiseBase.Then(Action onResolved, Action onRejected) + { + return Then(() => { onResolved(PromiseResult.None); }, onRejected); + } + /// /// Helper function to invoke or register resolve/reject handlers. /// @@ -905,6 +792,16 @@ public IPromise ThenAll(Func> chain) return Then(() => All(chain())); } + /// + /// Chain an enumerable of promises, all of which must resolve. + /// The resulting promise is resolved when all of the promises have resolved. + /// It is rejected as soon as any of the promises have been rejected. + /// + IPromiseBase IPromiseBase.ThenAll(Func> chain) + { + return ThenAll(chain); + } + /// /// Chain an enumerable of promises, all of which must resolve. /// Converts to a non-value promise.