示例#1
0
module.exports = function *() {
  while (1) {
    let screen = this.read();

    if (mainPageRe.test(screen)) {
      break;
    }

    // 返回前一頁
    this.left();

    // 等待更多資料
    let key = yield this.wait({
      cmds: this.waitForMoreData(),
      timeout: wait(2000)
    });

    // 不知道發生了什麼意外,讓他回到 boot 狀態
    if (key === 'timeout') {
      this.state('boot');
      return;
    }

    yield wait(500);
  }

  this.state('main');
};
示例#2
0
 it('should expire set values when set\'s optional expiresIn argument is provided', function *() {
   var key = 'test-expire-key';
   var input = 'string';
   yield store.set(key, input, 1);
   var output = yield store.get(key);
   assert.equal(input, output);
   yield wait(100);
   output = yield store.get(key);
   assert.equal(input, output);
   yield wait(1000);
   output = yield store.get(key);
   assert.ok(!output);
 });
示例#3
0
 co(function *() {
   while (this._isStarted || this._isRunning) {
     yield wait(100);
   }
   this._isStopping = false;
   this.emit('status.didChange');
 }.bind(this)).catch(function(err) {
示例#4
0
co(function *() {
  var n = 50

  while (n-- > 0) {
    yield wait(100)
    ch(n)
  }
})()
示例#5
0
 yield cli.action(`Waiting for ${cli.color.green(domain.hostname)}`, co(function * () {
   while (domain.status === 'pending') {
     yield wait(5000)
     domain = yield heroku.get(`/apps/${context.app}/domains/${domain.id}`)
   }
   if (domain.status === 'succeeded' || domain.status === 'none') return
   throw new Error(`The domain creation finished with status ${domain.status}`)
 }))
示例#6
0
function* waitForResults() {
	var val = 1;
	while(val === 1) {
		//Wait until value of the data pin is 0
		yield wait(10);
		val = yield this.dataPin.read();
	}
}
示例#7
0
co(function *() {
  var n = 10;
  
  while (n-- > 0) {
    yield wait(100);
    try {
      ch(n);
    } catch(err) {
      console.log(err.message);
    }

    if (n === 5) {
      ch.close();
    }
  }
})();
示例#8
0
  co(function*() {
    var stream = through();

    process.nextTick(function() {
      (function next() {
        stream.queue('foo');
        if (--times) setTimeout(next, 10);
        else stream.end();
      })();
    });

    var chunk;
    while (chunk = yield read(stream)) {
      t.equal(chunk, 'foo', 'data event');
      yield wait(50);
    }

    t.ok(true, 'ended');
  }, t.error.bind(t));
示例#9
0
文件: api.js 项目: duojs/duo
    it('should update dependencies when the manifest changes', function* () {
      var duo = build('manifest-modify');

      var a = path('manifest-modify', 'component-a.json');
      var b = path('manifest-modify', 'component-b.json');
      var manifest = path('manifest-modify', 'component.json');

      // write manifest a
      yield fs.writeFile(manifest, yield fs.readFile(a, 'utf8'));
      var adeps = yield duo.install();

      yield wait(1000); // need to wait so mtime changes

      // write manifest b
      yield fs.writeFile(manifest, yield fs.readFile(b, 'utf8'));
      var bdeps = yield duo.install();

      // assertions
      assert.notDeepEqual(Object.keys(adeps), Object.keys(bdeps));

      // cleanup
      yield fs.unlink(manifest);
    });
示例#10
0
文件: Game.js 项目: moneypot/shiba
GameStore.prototype.fillMissing = function*(data) {
  debug('Checking for missing games before: %d', data.game_id);

  let maxGameId = data.state === 'ENDED' ? data.game_id : data.game_id - 1;

  // Get ids of missing games. TODO: move this constants
  let ids = yield* Pg.getMissingGames(3190000, maxGameId);

  // Import them from the web.
  for (let id of ids) {
    debug('Importing missing id: %d', id);
    try {
      yield* this.importGame(id);
    } catch(err) {
      // Message error but continue. Could be an unterminated game.
      console.error('Error while importing game %d:', id, err.stack || err);
    }
    yield wait(1500);
  }

  // Finally replace the store with the current games. TODO: Yes, there is a
  // race condition here, but this store isn't really used anyway...
  this.store = yield* Pg.getLastGames();
};
示例#11
0
  return co(function* () {
    var lastError;
    while (--tries >= 0) {
      try {
        if (opts.debug) debug(`connection attempt ${opts.type}://${host}:${port}`);

        yield connect(host, port);
        if (opts.debug) debug(`connected`);

        return;
      }
      catch (err) {
        if (opts.debug) debug(`connection attempt failed, retrying in ${opts.retryInterval}ms, retries: ${tries}, err: ${err}`);
        lastError = err;
        yield wait(opts.retryInterval);
      }
    }

    if (opts.debug) debug(`all retries failed`);

    // if we're here, we failed to connect after retries and timeouts
    throw new Error('Failed to connect: ' + lastError.message);
    // use partial application of .bind() to call cb w/o an error
  }).then(cb && cb.bind(null, null))
示例#12
0
 this.waitStop = function *() {
   while (this._isStopping) {
     yield wait(100);
   }
 }
示例#13
0
 yield process(gen(), function*(data){
   console.log('process: %s', data);
   yield wait(5000);
   console.log('done: %s', data);
 });
示例#14
0
 ip: function *() {
     yield wait(1000);
     return this.ip;
 },
示例#15
0
 yield process(gen(), function*(data){
   concurrency++;
   max = Math.max(concurrency, max);
   yield wait(200);
   concurrency--;
 });
示例#16
0
 yield process(gen(), function*(data){
   yield wait(0);
 });
示例#17
0
var job = function *() {
  console.log('Doing something...');
  yield wait(1000);
}
示例#18
0
 function* gen(){
   yield wait(0);
   return Math.random();
 }
示例#19
0
 getSum: function *(a, b) {
     yield wait(1000);
     return a + b;
 },
示例#20
0
 return function *() {
     yield wait(3000);
     return '<p>callback Gen</p>';
 };
示例#21
0
文件: app.js 项目: geta6/koa-ws
app.ws('track', function*(){
  this.sockets.emit('track', yield play(this.param.guid));
  this.socket.playing = this.param.guid;
  yield wait(15 * 1000);
  this.sockets.emit('track', yield stop(this.param.guid));
});
示例#22
0
 var read = sse(function*(){
   yield wait(1000);
   return Date.now() + '';
 });
 return foreach(types, function *(type) {
   yield wait(ParserExecuter.interval);
   result[type] = JSON.parse(yield ParserExecuter.exec(logPath, type, oldVersion, newVersion));
 }).then(() => {