Beispiel #1
0
        public static IPromise <T> Then <T>(this Deferred <T> deferred, Action <T> success, Action <Exception> fail = null)
        {
            var promise = deferred.Then(x =>
            {
                success(x);
                return(x);
            });

            if (fail != null)
            {
                promise.Fail(fail);
            }

            return(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);
                    });
                });
Beispiel #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());
        }
Beispiel #4
0
 public Document(int id, string fullPath)
 {
     Id       = id;
     FullPath = fullPath;
     Ready    = new Deferred <Document>();
 }
Beispiel #5
0
 public static IPromise <T> Then <T>(this Deferred <T> deferred, Action success, Action <Exception> fail = null)
 {
     return(Then(deferred, x => success(), fail));
 }