Example #1
0
        public static Promise All(IEnumerable <Promise> promises)
        {
            Guard.ArgumentNotNull(promises, "promises");
            List <Promise> list = new List <Promise>(promises);

            if (list.Count == 0)
            {
                return(new Promise(PromiseState.Fulfilled, new EcmaArray()));
            }
            Promise promise = new Promise();
            int     count   = 0;

            foreach (Promise p in list)
            {
                p.ContinueWith(other => {
                    if (other.State == PromiseState.Rejected)
                    {
                        promise.RejectSelf(other.Value);
                    }
                    else if (++count == list.Count)
                    {
                        promise.ResolveSelf(new EcmaArray(list.Select(v => v.Value).ToList()));
                    }
                });
            }
            return(promise);
        }
Example #2
0
        public static Promise Reject(EcmaValue value)
        {
            Promise promise = new Promise();

            promise.RejectSelf(value);
            return(promise);
        }