@cloudbase/js-sdk
Version:
cloudbase javascript sdk
23 lines (22 loc) • 794 B
JavaScript
export var createPromiseCallback = function () {
var cb = function () { };
if (!Promise) {
cb.promise = {};
var throwPromiseNotDefined = function () {
throw new Error('Your Node runtime does support ES6 Promises. ' +
'Set "global.Promise" to your preferred implementation of promises.');
};
Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined });
Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined });
return cb;
}
var promise = new Promise(function (resolve, reject) {
cb = function (err, data) {
if (err)
return reject(err);
return resolve(data);
};
});
cb.promise = promise;
return cb;
};