Skip to content

johnhof/comise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

comise

Build Status

Promises + Co

Usage

Simple

let co = require('co');
let comise = require('comise');

co(function *() {
  let result = yield comise(function *() {
    return 'It worked!';
  });

  console.log(result); // It worked!
});

Context Binding

'use strict';

let co = require('co');
let comise = require('../lib/comise');

class Foo {
  bar() {
    return comise(function *() {
      let work = yield this.work();
      return 'Did ' + work + ' Work';
    }, this);
  }

  work() {
    return comise(function *() {
      let i = 0;
      for (i = 0; i < 1000; i++) {}
      return i;
    }, this);
  }
}

co(function *() {
  let foo = new Foo();
  let result = yield foo.bar();
  console.log(result); // Did 1000 Work
}).catch((err) => { console.log(err); });