spawnWorkers(concurrency) { const self = this; for(let i = 0; i < concurrency; i++) { co(function* () { while(true) { const task = yield self.nextTask(); yield task; } }); } }
co.wrap(function * (libTplPath, localTplPath) { let tpl try { yield thenFs.stat(localTplPath) tpl = yield thenFs.readFile(localTplPath, 'utf-8') } catch (e) { tpl = yield thenFs.readFile(libTplPath, 'utf-8') yield thenFs.writeFile(localTplPath, tpl) } return tpl })
describe('Cursors', () => { it('should work with no suffix', co.wrap(function * () { const db = datastore('') yield db.insert([ { id: 2, name: 'Tim' }, { id: 1, name: 'Tom' } ]) const res = yield db.cfind().sort({ name: -1 }).projection({ name: 1 }).exec() assert.equal(res[0].name, 'Tom') assert.equal(res[1].name, 'Tim') assert.equal(typeof res[0].id, 'undefined') })) })
function build(opts) { opts = Object.assign({}, opts); const appRoot = opts.applicationRoot; assert(appRoot, '`options.applicationRoot` required'); opts.outputDir = opts.outputDir || pathUtil.join(appRoot, 'public'); const settings = util.loadSettings(appRoot); console.log('build assets %s -> %s', appRoot, opts.outputDir); const builder = new Builder(settings); return co(function* () { yield builder.buildApp(opts); }); }
lockjs .command('lock <projectPath> <entryPoint> <dest>') .description('lock specified node.js project and generate a public key') .action(function (projectPath, entryPoint, dest) { co(lock(projectPath, dest, entryPoint)).catch(console.error) })
co(function* () { Browser.setCharset('www.caobi45.com', 'gb2312'); const ret = yield Browser.GET('http://www.caobi45.com/index.html'); console.log(ret); }).catch((err) => { console.error(err); });
route.get('/user',function(req,res,next){ co(function*(){ var user = yield User.findOne({"_id" : req.query.id}).populate("friends songs"); if(!user) return Config.FAIL("0003"); return Config.SUCCESS(user); }).then(function(data){ res.json(data); }, function(e){ logger.info(e); }); });
co(function* () { /* load Strategies */ const strategiesPath = archFs.join(locations.APP_MIN_DIR, config.paths.strategies); if (yield archFs.exist(strategiesPath)) { yield archFs.loadAll( strategiesPath, (loadedModule) => { loadedModule(server); }); } })
describe('#count()', () => { it('should return the number of documents in the database', co.wrap(function * () { let count = yield DB.count({}) assert.equal(count, 3) })) it('should work with cursors', co.wrap(function * () { const count = yield DB.ccount({}).limit(2).exec() assert.equal(count, 2) })) })
co(function*() { var cookies = yield cookiePool.collectAll(); if (cookies.toString().indexOf('SNUID=') != -1) { yield cookiePool.destroy(); yield cookiePool.save(cookies); console.log(cookies.join(' ')); console.log('update cookies success'); } else { console.log('update cookies error'); } });
co.wrap(function *(query){ connection = new mssql.Connection(config); yield connection.connect(); var request = new mssql.Request(connection); var recordset = yield request.query(query); return recordset; })
const updateLicense = () => { return co(function*() { try { yield* readLicense(); logger.warn('update cluster with %s workers', workersCount); updateWorkers(); } catch (err) { logger.error('updateLicense error:\r\n%s', err.stack); } }); }
rollback() { const command = this; return co(function* () { if (command.trans) { yield command.trans.rollback(); command.trans = null; } }); }
co( function * () { let content = yield httpclient.httppostsimple("http://192.168.23.212", 33133 , {"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] },'root','111111' ) console.info(content); } )