original_string: protected function spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false) {
  
          // Using default timeout which is pretty high.
          if (!$timeout) {
              $timeout = self::get_timeout();
          }
          if ($microsleep) {
              // Will sleep 1/10th of a second by default for self::get_timeout() seconds.
              $loops = $timeout * 10;
          } else {
              // Will sleep for self::get_timeout() seconds.
              $loops = $timeout;
          }
  
          // DOM will never change on non-javascript case; do not wait or try again.
          if (!$this->running_javascript()) {
              $loops = 1;
          }
  
          for ($i = 0; $i < $loops; $i++) {
              // We catch the exception thrown by the step definition to execute it again.
              try {
                  // We don't check with !== because most of the time closures will return
                  // direct Behat methods returns and we are not sure it will be always (bool)false
                  // if it just runs the behat method without returning anything $return == null.
                  if ($return = call_user_func($lambda, $this, $args)) {
                      return $return;
                  }
              } catch (Exception $e) {
                  // We would use the first closure exception if no exception has been provided.
                  if (!$exception) {
                      $exception = $e;
                  }
              }
  
              if ($this->running_javascript()) {
                  if ($microsleep) {
                      usleep(100000);
                  } else {
                      sleep(1);
                  }
              }
          }
  
          // Using coding_exception as is a development issue if no exception has been provided.
          if (!$exception) {
              $exception = new coding_exception('spin method requires an exception if the callback does not throw an exception');
          }
  
          // Throwing exception to the user.
          throw $exception;
      }
code: protected function spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false) {
  
          // Using default timeout which is pretty high.
          if (!$timeout) {
              $timeout = self::get_timeout();
          }
          if ($microsleep) {
              // Will sleep 1/10th of a second by default for self::get_timeout() seconds.
              $loops = $timeout * 10;
          } else {
              // Will sleep for self::get_timeout() seconds.
              $loops = $timeout;
          }
  
          // DOM will never change on non-javascript case; do not wait or try again.
          if (!$this->running_javascript()) {
              $loops = 1;
          }
  
          for ($i = 0; $i < $loops; $i++) {
              // We catch the exception thrown by the step definition to execute it again.
              try {
                  // We don't check with !== because most of the time closures will return
                  // direct Behat methods returns and we are not sure it will be always (bool)false
                  // if it just runs the behat method without returning anything $return == null.
                  if ($return = call_user_func($lambda, $this, $args)) {
                      return $return;
                  }
              } catch (Exception $e) {
                  // We would use the first closure exception if no exception has been provided.
                  if (!$exception) {
                      $exception = $e;
                  }
              }
  
              if ($this->running_javascript()) {
                  if ($microsleep) {
                      usleep(100000);
                  } else {
                      sleep(1);
                  }
              }
          }
  
          // Using coding_exception as is a development issue if no exception has been provided.
          if (!$exception) {
              $exception = new coding_exception('spin method requires an exception if the callback does not throw an exception');
          }
  
          // Throwing exception to the user.
          throw $exception;
      }
code_tokens: protected function spin ( $ lambda , $ args = false , $ timeout = false , $ exception = false , $ microsleep = false ) { // Using default timeout which is pretty high. if ( ! $ timeout ) { $ timeout = self :: get_timeout ( ) ; } if ( $ microsleep ) { // Will sleep 1/10th of a second by default for self::get_timeout() seconds. $ loops = $ timeout * 10 ; } else { // Will sleep for self::get_timeout() seconds. $ loops = $ timeout ; } // DOM will never change on non-javascript case; do not wait or try again. if ( ! $ this -> running_javascript ( ) ) { $ loops = 1 ; } for ( $ i = 0 ; $ i < $ loops ; $ i ++ ) { // We catch the exception thrown by the step definition to execute it again. try { // We don't check with !== because most of the time closures will return // direct Behat methods returns and we are not sure it will be always (bool)false // if it just runs the behat method without returning anything $return == null. if ( $ return = call_user_func ( $ lambda , $ this , $ args ) ) { return $ return ; } } catch ( Exception $ e ) { // We would use the first closure exception if no exception has been provided. if ( ! $ exception ) { $ exception = $ e ; } } if ( $ this -> running_javascript ( ) ) { if ( $ microsleep ) { usleep ( 100000 ) ; } else { sleep ( 1 ) ; } } } // Using coding_exception as is a development issue if no exception has been provided. if ( ! $ exception ) { $ exception = new coding_exception ( 'spin method requires an exception if the callback does not throw an exception' ) ; } // Throwing exception to the user. throw $ exception ; }
docstring: Executes the passed closure until returns true or time outs.
  
  In most cases the document.readyState === 'complete' will be enough, but sometimes JS
  requires more time to be completely loaded or an element to be visible or whatever is required to
  perform some action on an element; this method receives a closure which should contain the
  required statements to ensure the step definition actions and assertions have all their needs
  satisfied and executes it until they are satisfied or it timeouts. Redirects the return of the
  closure to the caller.
  
  The closures requirements to work well with this spin method are:
  - Must return false, null or '' if something goes wrong
  - Must return something != false if finishes as expected, this will be the (mixed) value
  returned by spin()
  
  The arguments of the closure are mixed, use $args depending on your needs.
  
  You can provide an exception to give more accurate feedback to tests writers, otherwise the
  closure exception will be used, but you must provide an exception if the closure does not throw
  an exception.
  
  @throws Exception If it timeouts without receiving something != false from the closure
  @param Function|array|string $lambda The function to execute or an array passed to call_user_func (maps to a class method)
  @param mixed $args Arguments to pass to the closure
  @param int $timeout Timeout in seconds
  @param Exception $exception The exception to throw in case it time outs.
  @param bool $microsleep If set to true it'll sleep micro seconds rather than seconds.
  @return mixed The value returned by the closure
docstring_tokens: Executes the passed closure until returns true or time outs .