/// <summary> /// Takes a function that yields an enumerable of promises. /// Converts to a non-value promise. /// Returns a promise that resolves when the first of the promises has resolved. /// Yields the value from the first promise that has resolved. /// </summary> public IPromise ThenRace(Func <PromisedT, IEnumerable <IPromise> > chain) { return(Then(value => Promise.Race(chain(value)))); }
public IPromise <ConvertedT> Transform <ConvertedT>(Func <PromisedT, ConvertedT> transform) { // Argument.NotNull(() => transform); return(Then(value => Promise <ConvertedT> .Resolved(transform(value)))); }
/// <summary> /// Takes a function that yields an enumerable of promises. /// Returns a promise that resolves when the first of the promises has resolved. /// Yields the value from the first promise that has resolved. /// </summary> public IPromise <ConvertedT> ThenRace <ConvertedT>(Func <PromisedT, IEnumerable <IPromise <ConvertedT> > > chain) { return(Then(value => Promise <ConvertedT> .Race(chain(value)))); }
/// <summary> /// 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. /// </summary> public IPromise ThenAll(Func <PromisedT, IEnumerable <IPromise> > chain) { return(this.Then(value => Promise.All(chain(value)))); }
/// <summary> /// Complete the promise. Adds a default error handler. /// </summary> public void Done() { Catch(ex => Promise.PropagateUnhandledException(this, ex) ); }
/// <summary> /// Takes a function that yields an enumerable of promises. /// Converts to a value promise. /// Returns a promise that resolves when the first of the promises has resolved. /// </summary> public IPromise <ConvertedT> ThenRace <ConvertedT>(Func <IEnumerable <IPromise <ConvertedT> > > chain) { return(Then(() => Promise <ConvertedT> .Race(chain()))); }
/// <summary> /// Chain an enumerable of promises, all of which must resolve. /// Returns a promise for a collection of the resolved results. /// 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. /// </summary> public IPromise <IEnumerable <ConvertedT> > ThenAll <ConvertedT>( Func <PromisedT, IEnumerable <IPromise <ConvertedT> > > chain) { return(this.Then(value => Promise <ConvertedT> .All(chain(value)))); }
/// <summary> /// 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. /// </summary> public IPromise ThenAll(Func <IEnumerable <IPromise> > chain) { return(Then(() => Promise.All(chain()))); }
/// <summary> /// Takes a function that yields an enumerable of promises. /// Returns a promise that resolves when the first of the promises has resolved. /// </summary> public IPromise ThenRace(Func <IEnumerable <IPromise> > chain) { return(Then(() => Promise.Race(chain()))); }
/// <summary> /// Add a resolved callback, a rejected callback and a progress callback. /// The resolved callback chains a value promise (optionally converting to a different value type). /// </summary> public IPromise <ConvertedT> Then <ConvertedT>( Func <PromisedT, IPromise <ConvertedT> > onResolved, Func <Exception, IPromise <ConvertedT> > onRejected, Action <float> 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); var resultPromise = new Promise <ConvertedT>(); resultPromise.WithName(Name); Action <PromisedT> resolveHandler = null; if (IsActionHandlersResolveValid()) { resolveHandler = v => { onResolved(v) .Progress(progress => resultPromise.ReportProgress(progress)) .Then( // Should not be necessary to specify the arg type on the next line, but Unity (mono) has an internal compiler error otherwise. chainedValue => resultPromise.Resolve(chainedValue), ex => resultPromise.Reject(ex) ); }; } Action <Exception> rejectHandler = null; if (IsActionHandlersRejectValid()) { rejectHandler = ex => { if (onRejected == null) { resultPromise.Reject(ex); return; } try { onRejected(ex) .Then( chainedValue => resultPromise.Resolve(chainedValue), callbackEx => resultPromise.Reject(callbackEx) ); } catch (Exception callbackEx) { resultPromise.Reject(callbackEx); } }; } ActionHandlers(resultPromise, resolveHandler, rejectHandler); if (onProgress != null) { ProgressHandlers(this, onProgress); } return(resultPromise); }
public IPromise Untyped() { return(Then(x => Promise.Resolved())); }
private Promise(PromiseState initialState) { CurState = initialState; Id = Promise.NextId(); }
protected ASignal() { OnResult = new RSG.Promise(); }
public static IPromise <T> v <T>(T value) { return(Promise <T> .Resolved(value)); }