I want to instantiate an object where the constructor performs async calls before returning. The purpose is to do async currying. I am using co. The below example fails. What am I doing wrong?
var co = require('co')
function asyncFunction() {
return new Promise(function (resolve) {
resolve()
})
}
function MyObject () {
co(function * () {
yield asyncFunction()
}).then(()=> {
this.runSomething = function() {
return 'something'
}
})
}
new MyObject().runSomething()
// TypeError: (intermediate value).runSomething is not a function