예제 #1
0
    /// <summary>
    /// Returns promise that is resolved when jsSearchString evaluates to a non-null value or rejected if it evaluates to null after n iterations.
    /// </summary>
    /// <returns>The until ready prom.</returns>
    /// <param name="jsSearchString">Js search string.</param>
    /// <param name="iterations">Iterations.</param>
    /// <param name="iterInterval">Iter interval.</param>
    private IPromise <JSONNode> WaitUntilReadyProm(string jsSearchString = "", int iterations = 10, float iterInterval = 0.25f)
    {
        Debug.Log("Looking for js: " + jsSearchString);
        Promise <JSONNode> returnProm = new Promise <JSONNode>();

        IPromise waitProm = Promise.Resolved();

        for (int i = 0; i < iterations; i++)
        {
            int iter = i;
            waitProm = waitProm.Then(() => {
                //Debug.Log(string.Format("Going through iter {0} in search {1}", iter, jsSearchString));

                if (returnProm.CurState != PromiseState.Pending)
                {
                    //Debug.Log("Return empty promise from 1");
                    return(Promise.Resolved());
                }
                else
                {
                    return(browser.EvalJS(jsSearchString)
                           .Then((res) => {
                        //Debug.LogFormat("Checking js {0} with result {1} in iter {2}", jsSearchString, res.Value, iter);
                        if (!res.IsNull)
                        {
                            Debug.Log(string.Format("{0} is Found after {1} iterations", jsSearchString, iter));
                            returnProm.Resolve(res);
                        }
                        else if (iter == iterations - 1)
                        {
                            Debug.Log(string.Format("NOT Found after {0} iterations", iter));
                            returnProm.Resolve(null);
                        }

                        //Debug.Log("Return empty promise from 2");
                        return promTimer.WaitFor(iterInterval);
                    })
                           .Catch((exc) => {
                        Debug.LogWarningFormat("Sequence exception: {0}", exc.Message);
                        returnProm.Reject(new System.Exception("Sequence exprerienced exception: " + exc.Message));
                    }));
                }
            });
        }
        waitProm.Catch((exc) => Debug.LogWarningFormat("Caught exception in waiting promise: {1}", exc.Message));
        //Debug.Log("Returning prom");
        return(returnProm);
    }
예제 #2
0
 private IPromise TimeoutPromise(float seconds)
 {
     return(promiseTimer.WaitFor(seconds));
 }
예제 #3
0
 public IPromise WaitFor(float seconds)
 {
     return(_promiseTimer.WaitFor(seconds));
 }