comise
v1.0.1
Published
Promises + Co
Downloads
11
Readme
comise
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); });