Saturday 20 May 2017

Using bluebirdjs with Google Cloud Datastore node client library

I am having a strange issue trying to use bluebirds promises with google's cloud client libraries. After digging around Google's libs, I noticed in the common functions, there is a util file with promisify functions. I assume these are being used to promisify the datastore acess functions, as they can be used as a promise. My problem comes in because I am writing a Google Cloud Function which executes based on a PubSub trigger. At the end of the function I need to execute the callback() function to 'end' the function.

I wanted to use bluebirds finally() api on the promises to make sure callback is always called. But, when trying to access the datastore it returns it's own type of Promise and not a bluebird promise, even if I try call:

const Promise = require('bluebird');
const Datastore = Promise.promisifyAll(require('@google-cloud/datastore'));
const datastore = Promise.promisifyAll(
Datastore({
projectId: 'xxxx'
}));

But this doesn't seem to 'replace' Google's promises with bluebirds. Is there a way to do this?



via SeanSWatkins

No comments:

Post a Comment