How to use the co function in co

To help you get started, we’ve selected a few co examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beakerbrowser / beaker / app / builtin-pages / views / site.js View on Github external
function fetchArchiveInfo() {
  return co(function* () {
    console.log('Looking up', siteKey)

    // run request
    siteInfo = yield datInternalAPI.getArchiveInfo(siteKey)
    siteEntriesTree = entriesListToTree(siteInfo)
    siteName = (siteInfo.name || siteInfo.short_name || 'Untitled')
    document.title = siteName + ' - Site Editor'

    console.log(siteName, siteInfo)
  }).catch(err => {
    console.warn('Failed to fetch archive info', err)
    siteError = err
  })
}
github owncloud / contacts / js / dav / lib / transport.js View on Github external
send(request, url, options={}) {
    return co(function *() {
      let sandbox = options.sandbox;
      let transformRequest = request.transformRequest;
      let transformResponse = request.transformResponse;
      let onerror = request.onerror;

      if (!('retry' in options)) options.retry = true;

      let result, xhr;
      try {
        let token = yield access(this.credentials, options);
        xhr = new XMLHttpRequest();
        if (sandbox) sandbox.add(xhr);
        xhr.open(request.method, url, true /* async */);
        xhr.setRequestHeader('Authorization', `Bearer ${token}`);
        if (transformRequest) transformRequest(xhr);
        xhr.setRequestHeader('requesttoken', oc_requesttoken);
github christkv / okr / client / src / store.jsx View on Github external
return new Promise((resolve, reject) => {
      co(function*() {
        // Only connect if not already connected
        if(!self.backend.isConnected()) {
          yield self.backend.connect(url)
        }

        // Resolve
        resolve(self);
      }).catch(reject);
    });
  }
github kudos / combine.fm / worker.js View on Github external
function search(data, done) {
  const share = data.share;
  const service = services.find(item => data.service.id === item.id);
  debug(`Searching on: ${service.id}`);
  co(function* gen() { // eslint-disable-line no-loop-func
    try {
      const match = yield service.search(share);

      if (match.id) {
        models.match.create({
          trackId: share.type === 'track' ? share.id : null,
          albumId: share.type === 'album' ? share.id : null,
          externalId: match.id.toString(),
          service: match.service,
          name: match.name,
          streamUrl: match.streamUrl,
          purchaseUrl: match.purchaseUrl,
          artworkSmall: match.artwork.small,
          artworkLarge: match.artwork.large,
        });
      } else {
github marmelab / javascript-boilerplate / bin / loadFixtures.js View on Github external
#!./node_modules/babel/bin/babel-node.js

import co from 'co';
import config from 'config';
import { PgPool } from 'co-postgres-queries';
import fixturesFactory from '../src/common/e2e/lib/fixturesLoader';

co(function* () {
    const db = new PgPool(config.apps.api.db);
    const fixtureLoader = fixturesFactory(db);
    yield fixtureLoader.removeAllFixtures();
    yield fixtureLoader.loadDefaultFixtures();
}).then(() => {
    console.log('Fixtures successfully loaded!');
    process.exit(0);
}).catch(error => {
    console.error(error, { trace: error.stack });
    process.exit(1);
});
github ticruz38 / Ambrosia / server / database.js View on Github external
export function getRestaurant(id, rootValue) {
  return co(function*() {
    var p = new Promise(function(resolve, reject) {
      r.table('restaurant').get(id).run(rootValue.conn, function(err, res) {
        if (err) reject(err);
        resolve(res);
      });
    });
    return yield p.then(function(value) {
      //console.log('database:getRestaurant:value', value);
      var data = value || null;
      return data;
    });
  });
}
github kudos / combine.fm / fixmissing.js View on Github external
item.matches.forEach((match) => {
      unmatched = unmatched.filter(id => match.service !== id);
    });
    if (unmatched.length > 0) {
      debug(`Matching ${unmatched.join(', ')}`);
      unmatched.forEach((toMatch) => {
        search({ share: item, service: { id: toMatch } });
      });
    } else {
      debug(`No broken matches for ${item.name}`);
    }
  });
  return Promise.resolve();
}

co(function* main() {
  yield find('album');
  yield find('track');
  setTimeout(() => {
    process.exit(0);
  }, 1000);
}).catch((err) => {
  debug(err.stack);
});
github esdoc / esdoc-hosting / src / ElasticSearch / ElasticSearcher.js View on Github external
_formatResult(result) {
    return co(this._formatResultAsync.bind(this, result));
  }
github ticruz38 / Ambrosia / server / database.js View on Github external
function getAnyRestaurants(rootValue) {
  return co(function*() {
    var p = new Promise((resolve, reject) => {
      r.table('restaurant').run(rootValue.conn, (err, res) => {
        if (err) throw err;
        res.toArray((err, res) => {
          if (err) throw err;
          resolve(res);
        });
      });
    });
    return yield p;
  });
}
github esdoc / esdoc-hosting / src / API.js View on Github external
search(req, res) {
    return co(function*(){
      const keyword = req.query.keyword;
      if (!keyword) {
        res.json({success: false, message: 'keyword is not found'});
        return;
      }

      const searcher = new ElasticSearcher();
      const result = yield searcher.search(keyword);
      res.json({success: true, result: result});
    });
  }
}