我有一个奇怪的问题,试图在谷歌云客户端库中使用bluebirds promise。 挖掘Google的libs后,我注意到在常用函数中,有一个具有promisify函数的util文件。 我假设这些被用来promisify数据存储接口函数,因为它们可以用作承诺。 我的问题出现了,因为我正在编写基于PubSub触发器执行的Google Cloud Function。 在函数结束时,我需要执行callback()
函数来'结束'函数。在Google Cloud Datastore节点客户端库中使用bluebirdjs
我想在承诺中使用蓝鸟finally()
api来确保始终调用回调函数。但是,当试图访问它返回它自己类型的承诺,而不是一个蓝鸟承诺,即使我尝试调用数据存储:
const Promise = require('bluebird');
const Datastore = Promise.promisifyAll(require('@google-cloud/datastore'));
const datastore = Promise.promisifyAll(
Datastore({
projectId: 'xxxx'
}));
但这似乎不是没有“取代” Google对蓝鸟的承诺。有没有办法做到这一点?
我目前的工作围绕:
dothing(value)
.then(function(){
return doAnotherThing(anothervalue);
})
.then(function(){
// Done
callback();
})
.catch(function(){
// Something went wrong
callback();
});
我知道这是不是是比finally()
得多,但它仍然感觉有点不雅