1 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
  2   this.timeout = timeout;
  3   this.latchFunction = latchFunction;
  4   this.message = message;
  5   this.totalTimeSpentWaitingForLatch = 0;
  6   jasmine.Block.call(this, env, null, spec);
  7 };
  8 
  9 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
 10 
 11 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
 12 
 13 jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
 14   var self = this;
 15   self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
 16   var latchFunctionResult;
 17   try {
 18     latchFunctionResult = self.latchFunction.apply(self.spec);
 19   } catch (e) {
 20     self.spec.fail(e);
 21     onComplete();
 22     return;
 23   }
 24 
 25   if (latchFunctionResult) {
 26     onComplete();
 27   } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
 28     var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
 29     self.spec.fail({
 30       name: 'timeout',
 31       message: message
 32     });
 33   } else {
 34     self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
 35     self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
 36   }
 37 };