/// <summary> /// 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. /// </summary> public static IPromise All(IEnumerable <IPromise> promises) { var promisesArray = promises.ToArray(); if (promisesArray.Length == 0) { return(Promise.Resolved()); } var remainingCount = promisesArray.Length; var resultPromise = new Promise(); resultPromise.WithName("All"); promisesArray.Each((promise, index) => { promise .Catch(ex => { if (resultPromise.CurState == PromiseState.Pending) { // If a promise errorred and the result promise is still pending, reject it. resultPromise.Reject(ex); } }) .Then(() => { --remainingCount; if (remainingCount <= 0) { // This will never happen if any of the promises errorred. resultPromise.Resolve(); } }) .Done(); }); return(resultPromise); }
public IPromise <List <Cookie> > GetCookies() { Cookie.Init(); List <Cookie> ret = new List <Cookie>(); if (!browser.IsReady || !browser.enabled) { return(Promise <List <Cookie> > .Resolved(ret)); } Promise <List <Cookie> > promise = new Promise <List <Cookie> >(); BrowserNative.GetCookieFunc getCookieFunc = delegate(BrowserNative.NativeCookie cookie) { try { if (cookie == null) { browser.RunOnMainThread(delegate { promise.Resolve(ret); }); cookieFuncs.Remove(promise); } else { ret.Add(new Cookie(this, cookie)); } } catch (Exception exception) { Debug.LogException(exception); } }; BrowserNative.zfb_getCookies(browser.browserId, getCookieFunc); cookieFuncs[promise] = getCookieFunc; return(promise); }
public IPromise <ConvertedT> Transform <ConvertedT>(Func <PromisedT, ConvertedT> transform) { return(Then((PromisedT value) => Promise <ConvertedT> .Resolved(transform(value)))); }
public IPromise <ConvertedT> Transform <ConvertedT>(Func <PromisedT, ConvertedT> transform) { // Argument.NotNull(() => transform); return(Then(value => Promise <ConvertedT> .Resolved(transform(value)))); }