Пример #1
0
        public IEnumerator BlockUntil()
        {
            var queueObj = new GameObject();
            var queue    = queueObj.AddComponent <FuseTools.AsyncQueue>();

            queue.Wait = 0.5f; // half a second of delay between queued items
            Assert.True(queue.IsReady);

            var promise = new RSG.Promise((resolve, reject) => {
            });

            queue.BlockUntil(promise);
            Assert.False(queue.IsReady);

            yield return(new WaitForSeconds(0.6f));

            Assert.False(queue.IsReady);

            promise.Resolve();
            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.4f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.11f));

            Assert.True(queue.IsReady);

            // cleanup
            Object.Destroy(queueObj);
        }
Пример #2
0
        public IEnumerator WhenReady()
        {
            var queueObj = new GameObject();
            var queue    = queueObj.AddComponent <FuseTools.AsyncQueue>();

            queue.Wait = 0.5f; // half a second of delay between queued items
            Assert.True(queue.IsReady);

            int counter       = 0;
            var remotePromise = new RSG.Promise();

            queue.WhenReady(() => new RSG.Promise((res, rej) => {
                counter += 1;
                remotePromise.Then(res);
            }));

            yield return(new WaitForSeconds(0.5f));

            remotePromise.Resolve();
            Assert.False(queue.IsReady); // 0.5 sec timeout
            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.15f));

            Assert.True(queue.IsReady);

            // cleanup
            Object.Destroy(queueObj);
        }
Пример #3
0
        public static RSG.IPromise <Proyecto26.ResponseHelper> Request(Proyecto26.RequestHelper request)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            Debug.Log("Request: " + request.Method + " " + request.Uri);

            if (request.BodyString != null)
            {
                Debug.Log("Request body: " + request.BodyString);
            }

            if (request.Timeout != null)
            {
                Debug.Log("Request will time out after " + request.Timeout + " seconds.");
            }

            var responsePromise = new RSG.Promise <Proyecto26.ResponseHelper>();

            Proyecto26.RestClient.Request(request)
            .Then(response =>
            {
                Debug.Log("Response received after " + stopwatch.Elapsed.Milliseconds + " milliseconds.");

                Debug.Log("Response status code: " + response.StatusCode);

                if (response.Text != null)
                {
                    Debug.Log("Response text: " + response.Text);
                }

                responsePromise.Resolve(response);
            })
            .Catch(error =>
            {
                Debug.LogError(error.Message + "\n" + error.StackTrace);

                throw error;
            });

            return(responsePromise);
        }
Пример #4
0
        public IEnumerator MixWaitUntilReadyAndBlockUntil()
        {
            var queueObj = new GameObject();
            var queue    = queueObj.AddComponent <FuseTools.AsyncQueue>();

            queue.Wait = 0.5f; // half a second of delay between queued items
            Assert.True(queue.IsReady);

            var promise = new RSG.Promise((resolve, reject) => {
            });

            queue.BlockUntil(promise);
            Assert.False(queue.IsReady);

            int counter = 0;

            queue.WaitUntilReady().Then(() => counter += 1);

            yield return(new WaitForSeconds(0.6f));

            Assert.False(queue.IsReady);
            Assert.AreEqual(counter, 0);
            promise.Resolve();
            Assert.False(queue.IsReady);
            Assert.AreEqual(counter, 0);
            yield return(new WaitForSeconds(0.4f));

            Assert.False(queue.IsReady);
            Assert.AreEqual(counter, 0);
            yield return(new WaitForSeconds(0.11f));

            Assert.False(queue.IsReady);
            Assert.AreEqual(counter, 1);
            yield return(new WaitForSeconds(0.4f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.1f));

            Assert.True(queue.IsReady);

            queue.WaitUntilReady().Then(() => counter += 1);
            Assert.False(queue.IsReady);
            Assert.AreEqual(counter, 2);

            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);

            // Call block until while not ready yet
            promise = new RSG.Promise((resolve, reject) => {
                counter += 10;
            });

            queue.BlockUntil(promise);
            Assert.AreEqual(counter, 12);

            Assert.False(queue.IsReady);
            promise.Resolve();

            // wait for timeout of last WaitUntilReady call to finish
            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.1f));

            Assert.False(queue.IsReady);

            // wait for timeout of last call to BlockUntil to finish
            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.2f));

            Assert.False(queue.IsReady);
            yield return(new WaitForSeconds(0.1f));

            Assert.True(queue.IsReady);

            // cleanup
            Object.Destroy(queueObj);
        }