Exemplo n.º 1
0
        public void OneWait1SecAndOther2SecsThenPrintResult()
        {
            if (!Application.isPlaying)
            {
                Debug.LogWarning("In order to see Promise working, please enter Play mode.");
                return;
            }

            Debug.Log("Creating promises");

            var promiseA = new Promise <string>();
            var promiseB = new Promise <int>();

            Functional.Ignore =
                from a in promiseA
                from b in promiseB
                select Functional.Do(() =>
                                     Debug.LogFormat("After all promise completion, got values '{0}' and '{1}'", a, b)
                                     );

            AfterSeconds(2.0f, () =>
            {
                promiseA.Complete("This is a promised value");
            });

            AfterSeconds(1.0f, () =>
            {
                promiseB.Complete(17);
            });
        }
Exemplo n.º 2
0
        public Promise <B> Select <B>(System.Func <A, B> select)
        {
            var pb = new Promise <B>();

            Then(a => pb.Complete(select(a)));

            return(pb);
        }
Exemplo n.º 3
0
        static Future <int> AsyncMethod()
        {
            var promise = new Promise <int>();
            var thread  = new Thread(() => {
                Thread.Sleep(100);
                promise.Complete(42);
            });

            thread.Start();
            return(promise.Future);
        }
        public Future Delay(int ms)
        {
            var promise = new Promise();
            var thread  = new Thread(() => {
                Thread.Sleep(ms);
                promise.Complete();
            });

            thread.Start();
            return(promise.Future);
        }
Exemplo n.º 5
0
        public Promise <C> SelectMany <B, C>(System.Func <A, Promise <B> > func, System.Func <A, B, C> select)
        {
            var pc = new Promise <C>();

            Then(a =>
            {
                var pb = func(a);
                pb.Then(b => pc.Complete(select(a, b)));
            });

            return(pc);
        }
Exemplo n.º 6
0
        public Promise <A> Where(System.Predicate <A> predicate)
        {
            var p = new Promise <A>();

            Then(a =>
            {
                if (predicate(a))
                {
                    p.Complete(a);
                }
            });

            return(p);
        }
Exemplo n.º 7
0
        public void Wait1SecondAndPrintResult()
        {
            if (!Application.isPlaying)
            {
                Debug.LogWarning("In order to see Promise working, please enter Play mode.");
                return;
            }

            Debug.Log("Creating a promise");

            var promise = new Promise <string>();

            promise.Then(v =>
                         Debug.LogFormat("After promise completion, got value '{0}'", v)
                         );

            AfterSeconds(1.0f, () =>
            {
                promise.Complete("This is a promised value");
            });
        }
Exemplo n.º 8
0
        public void Wait1SecondAndPrintResultWithLinq()
        {
            if (!Application.isPlaying)
            {
                Debug.LogWarning("In order to see Promise working, please enter Play mode.");
                return;
            }

            Debug.Log("Creating a promise");

            var promise = new Promise <string>();

            Functional.Ignore =
                from a in promise
                select Functional.Do(() =>
                                     Debug.LogFormat("After promise completion, got value '{0}'", a)
                                     );

            AfterSeconds(1.0f, () =>
            {
                promise.Complete("This is a promised value");
            });
        }