bluebird

How do I convert an existing callback API to promises?

谁说我不能喝 提交于 2020-01-17 18:01:02
问题 I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback ... window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { ... } request(function() { // change happened ... }); 3. Node style callback ("nodeback"): function getStuff(dat, callback) { ... } getStuff("dataParam", function(err, data) { ... }) 4. A whole library with node style callbacks: API; API.one(function(err, data)

How to promisify a braintree method?

萝らか妹 提交于 2020-01-17 06:07:29
问题 I'm having trouble promisifying a braintree method. Specifically, gateway.transaction.sale. https://developers.braintreepayments.com/reference/request/transaction/sale/node I am using node.js with the bluebird library for promisification. ... var sale = bluebird.promisify(gateway.transaction.sale); return sale({ amount: '10.00', paymentMethodNonce: nonce, }); }) .then( // doesn't reach here) .catch(// logs out error) Specifically, the .catch block at the bottom of the promise chain logs out:

How to promisify a braintree method?

假装没事ソ 提交于 2020-01-17 06:07:06
问题 I'm having trouble promisifying a braintree method. Specifically, gateway.transaction.sale. https://developers.braintreepayments.com/reference/request/transaction/sale/node I am using node.js with the bluebird library for promisification. ... var sale = bluebird.promisify(gateway.transaction.sale); return sale({ amount: '10.00', paymentMethodNonce: nonce, }); }) .then( // doesn't reach here) .catch(// logs out error) Specifically, the .catch block at the bottom of the promise chain logs out:

hexo g 或者 hexo s 报错FATAL Something's wrong.

a 夏天 提交于 2020-01-16 20:43:40
如题hexo在构建templates时出错 报错原因是 INFO Start processing FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html Template render error: (unknown path) [Line 282, Column 5] unexpected token: % at Object._prettifyError (/home/jason/Documents/blogs/node_modules/nunjucks/src/lib.js:36:11) at Template.render (/home/jason/Documents/blogs/node_modules/nunjucks/src/environment.js:524:21) at Environment.renderString (/home/jason/Documents/blogs/node_modules/nunjucks/src/environment.js:362:17) at Promise (/home/jason/Documents/blogs/node_modules/hexo/lib/extend

Do something N times using Bluebird Promises

回眸只為那壹抹淺笑 提交于 2020-01-15 06:23:28
问题 I am trying the Promises everyone is so excited about. They're are supposed to reduce code complexity which is a feature I've yet to observe. In my case, I have a function that returns Promise. The function invokes key up or down event on Android device over ADB. I call it like this: press(B_KEY, 3000, client, device) .then(function(result) {console.log("Key press done.");}); I would like to perform this action (call the press ) function) several times in sequence. I can do this manually:

Promise chain fundamental issue

一笑奈何 提交于 2020-01-13 13:05:21
问题 I'm trying to understand Promises. I've create some promise chains that work and others that don't. I've made progress but am apparently lacking a basic concept. For example, the following promise chain doesn't work. It's a silly example, but shows the issue; I'm trying to use Node's function randomBytes twice in a chain: var Promise = require("bluebird"); var randomBytes = Promise.promisify(require("crypto").randomBytes); randomBytes(32) .then(function(bytes) { if (bytes.toString('base64')

Promise chain fundamental issue

女生的网名这么多〃 提交于 2020-01-13 13:05:14
问题 I'm trying to understand Promises. I've create some promise chains that work and others that don't. I've made progress but am apparently lacking a basic concept. For example, the following promise chain doesn't work. It's a silly example, but shows the issue; I'm trying to use Node's function randomBytes twice in a chain: var Promise = require("bluebird"); var randomBytes = Promise.promisify(require("crypto").randomBytes); randomBytes(32) .then(function(bytes) { if (bytes.toString('base64')

Use ldapjs with bluebird promise

会有一股神秘感。 提交于 2020-01-13 10:42:09
问题 I posted something similar here: Use ldapjs with promise. Unfortunately, it is still unsolved. This time I tried bluebird and hopefully I can get some luck. // https://www.npmjs.com/package/ldapjs var Promise = require('bluebird'); var ldap = Promise.promisifyAll( require('ldapjs') ); var config = require('./config'); var print_r = require('print_r').print_r; var my_filter = "(&(objectCategory=person)(objectClass=user)" + "(cn=" + 'someone' + "))"; var ldap_username = config.ad.username; var

Unhandled rejection error Bluebird

南笙酒味 提交于 2020-01-13 10:29:21
问题 I have the following code. And it works as expected without throwing a unhandled rejection error. p = new Promise (fulfill, reject) -> reject new Error 'some error' p.catch (error) -> console.log error Now, the second code example does throw an unhandled rejection error. Can someone explain to me why this is happening when im clearly handling the error. p = new Promise (fulfill, reject) -> reject new Error 'some error' p.then -> console.log 'ok' p.catch (error) -> console.log error Btw. I'm

Can you avoid nesting altogether with Promises? [duplicate]

隐身守侯 提交于 2020-01-13 03:48:18
问题 This question already has answers here : How do I access previous promise results in a .then() chain? (17 answers) Closed 4 years ago . From what I understand one of the main selling points for Promises is the ability to write flat code (or, flatter than callback hell). Though it seems that in many cases we need to nest promises, in order to use closure. For example (from q's docs, though I use Bluebird): function authenticate() { return getUsername() .then(function (username) { return