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'); };
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); });
co(function *() { while (this._isStarted || this._isRunning) { yield wait(100); } this._isStopping = false; this.emit('status.didChange'); }.bind(this)).catch(function(err) {
co(function *() { var n = 50 while (n-- > 0) { yield wait(100) ch(n) } })()
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}`) }))
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(); } }
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(); } } })();
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));
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); });
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(); };
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))
this.waitStop = function *() { while (this._isStopping) { yield wait(100); } }
yield process(gen(), function*(data){ console.log('process: %s', data); yield wait(5000); console.log('done: %s', data); });
ip: function *() { yield wait(1000); return this.ip; },
yield process(gen(), function*(data){ concurrency++; max = Math.max(concurrency, max); yield wait(200); concurrency--; });
yield process(gen(), function*(data){ yield wait(0); });
var job = function *() { console.log('Doing something...'); yield wait(1000); }
function* gen(){ yield wait(0); return Math.random(); }
getSum: function *(a, b) { yield wait(1000); return a + b; },
return function *() { yield wait(3000); return '<p>callback Gen</p>'; };
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)); });
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(() => {