Example #1
0
        public static IPromise <IPromise[]> When(params IPromise[] promises)
        {
            var def = new Deferred <IPromise[]>();

            foreach (var prom in promises)
            {
                prom.Done(() =>
                {
                    lock (promises)
                    {
                        if (promises.All(p => p.IsResolved()))
                        {
                            def.Resolve(promises);
                        }
                    }
                })
                .Fail((error) =>
                {
                    if (promises.All(p => !p.IsPending()))
                    {
                        def.Reject();
                    }
                });
            }
            return(def.Promise());
        }
        public static Deferred <T> AutoComplete <T>(this Scintilla editor, int length, bool cancel, IDictionary <string, T> data, bool allItem = true)
        {
            _autoCompleteTimer?.Stop();

            var defer = new Deferred <T>();

            if (data.Count == 0)
            {
                editor.AutoCCancel();
                defer.Reject();
                return(defer);
            }

            _autoCompleteTimer = Redux.Timer.Timeout(100, () =>
            {
                editor.SafeInvoke(delegate
                {
                    var items = data.Keys.Take(MaxAutoCompleteItems).OrderBy(x => x.StartsWith("@") ? "\0" : x).ToArray();
                    var list  = (data.Count <= 20 && allItem && !cancel ? "<All>" + AutoCompleteSeprator : string.Empty) + string.Join(AutoCompleteSeprator.ToString(), items);

                    editor.AutoCShow(length, list);

                    _autoCompleteDeferred = new Deferred <string>();
                    _autoCompleteDeferred.Then(x =>
                    {
                        if (x == "<All>" && allItem && !cancel)
                        {
                            editor.AutoCCancel();
                            editor.AddText(string.Join(",", items.Take(20)));
                            return;
                        }

                        if (data.TryGetValue(x, out T d))
                        {
                            defer.Resolve(d);
                        }
                        if (cancel)
                        {
                            editor.AutoCCancel();
                        }
                    })
                    .Fail(x =>
                    {
                        defer.Reject(x);
                    });
                });
Example #3
0
        public virtual IPromise Then(IPromise nextPromise)
        {
            var nextDeferred = new Deferred();

            this.Done(() =>
            {
                nextPromise
                .Done(() =>
                {
                    nextDeferred.Resolve();
                })
                .Fail((error) =>
                {
                    nextDeferred.Reject(error);
                });
            })
            .Fail((error) =>
            {
                nextDeferred.Reject(error);
            });
            return(nextDeferred.Promise());
        }