Ejemplo n.º 1
0
        /// <summary>
        /// Allows you to continuously make a root query, till the response is deemed ready.
        /// </summary>
        /// <param name="isReady">A <see cref="Delegates.PollUpdatedHandler"/> that determines if polling should stop by returning true</param>
        /// <param name="query">The query to be queried continuously</param>
        /// \code
        /// // Example that uses polling
        /// QueryRootQuery query = new QueryRootQuery();
        ///
        /// query.node(
        ///     buildQuery: node => node
        ///         .onCheckout(checkout => checkout.ready()),
        ///     id: "someCheckoutID""
        /// );
        ///
        /// PollUpdatedHandler isReadyHandler = (updatedQueryRoot) => {
        ///     var expectedNode = (Checkout) updatedQueryRoot.node();
        ///     return expectedNode.ready();
        /// };
        ///
        /// PollQuery(isReadyHandler, query, (response, error) => {
        ///     if (error == null) {
        ///         var checkout = (Checkout) response.node();
        ///         // checkout.ready() is true
        ///     }
        ///})
        public void PollQuery(PollUpdatedHandler isReady, QueryRootQuery query, QueryRootHandler callback)
        {
            const float POLL_DELAY_SECONDS = 0.5f;

            Query(query, (QueryRoot response, ShopifyError error) => {
                if (error != null)
                {
                    callback(response, error);
                }
                else
                {
                    if (isReady(response))
                    {
                        callback(response, null);
                    }
                    else
                    {
#if !SHOPIFY_MONO_UNIT_TEST
                        UnityTimeout.Start(POLL_DELAY_SECONDS, () => {
                            PollQuery(isReady, query, callback);
                        });
#else
                        PollQuery(isReady, query, callback);
#endif
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public IEnumerator TimeoutHalfSecond()
        {
            float startTime       = Time.time;
            bool  didCallCallback = false;

            UnityTimeout.Start(0.5f, () => {
                didCallCallback = true;
                float endTime   = Time.time;
                float timeDiff  = endTime - startTime;

                Assert.IsTrue(timeDiff >= 0.5f && timeDiff < 0.55f, "Timeout completed in 0.5 seconds");
            });

            yield return(new WaitForSeconds(0.6f));

            Assert.IsTrue(didCallCallback);
        }