I'm trying to promisify the the someAsyncMethod in the following code.
When I run the the code, the yielded promise of the someAsyncMethod is never resolved.
Can someone tell me what I'm doing wrong?
'use strict';
var someapi = require('./lib/absenceio');
var Promise = require('bluebird');
class CompanyController {
constructor(currentUser, parameters) {
}
* someAsyncMethod () {
return yield someapi.listReasons(); // returns a promise
}
}
Promise.coroutine(function*(){
var c = new CompanyController();
Promise.promisifyAll(c);
var res = yield c.someAsyncMethodAsync();
console.log('never reached');
})();
someAsyncMethod() is a generator function, which you can't yield directly, but you can delegate to it using yield*.
So, your code becomes this:
var res = yield* c.someAsyncMethod();
No need to promisify it (I'm not even sure what Bluebird does when asked to promisify a generator function).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With