Beispiel #1
0
 public static Promise <T> DisposeIfCanceled <T>(this CancellationToken cancellationToken, Func <Promise <T> > func) where T : class
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return(Promises.Disposed <T> ());
     }
     return(func());
 }
Beispiel #2
0
        public void TestSelect()
        {
            var actual = 0;

            Promises.Resolved(1.Wrap()).Select(_ => 2.Wrap()).Done(_ => actual++);
            Promises.Rejected <TWrapper <int> > (new Exception()).Select(_ => 2.Wrap()).Fail(_ => actual++);
            Promises.Disposed <TWrapper <int> > ().Select(_ => 2.Wrap()).Disposed(() => actual++);
            Promises.Resolved(1.Wrap()).Select <TWrapper <int> > (_ => {
                throw new Exception();
            }).Fail(_ => actual++);
            Assert.That(actual, Is.EqualTo(4));
        }
Beispiel #3
0
        public void TestWhere()
        {
            var actual = 0;

            Promises.Resolved(1.Wrap()).Where(n => n.val == 1).Done(_ => actual++);
            Promises.Resolved(1.Wrap()).Where(n => n.val == 2)
            .Done(_ => Assert.Fail()).Fail(_ => Assert.Fail())
            .Disposed(() => actual++);
            Promises.Rejected <TWrapper <int> > (new Exception()).Where(_ => true).Fail(_ => actual++);
            Promises.Disposed <TWrapper <int> > ().Where(_ => true).Disposed(() => actual++);
            Promises.Resolved(1.Wrap()).Where(_ => {
                throw new Exception();
            }).Fail(_ => actual++);
            Assert.That(actual, Is.EqualTo(5));
        }
Beispiel #4
0
        public Promise <T> Create(List <Promise <T> > promises)
        {
            if (promises.Count == 0)
            {
                return(Promises.Disposed <T> ());
            }

            nonResolvedCount = 0;
            size             = promises.Count;
            deferred         = new Deferred <T>();

            foreach (var each in promises)
            {
                ObservePromise(each);
            }
            return(deferred);
        }