How to Promisify this function – nodejs [duplicate]

You have the error because create() is not a Promise. Promisifying an async function is quite easy (nodejs has a built-in Promise support nowadays): function createTicket(ticket) { // 1 – Create a new Promise return new Promise(function (resolve, reject) { // 2 – Copy-paste your code inside this function client.tickets.create(ticket, function (err, req, result) { … Read more

Make angular.forEach wait for promise after going to next object

Before ES2017 and async/await (see below for an option in ES2017), you can’t use .forEach() if you want to wait for a promise because promises are not blocking. Javascript and promises just don’t work that way. You can chain multiple promises and make the promise infrastructure sequence them. You can iterate manually and advance the … Read more

Page transition animations with Angular 2.0 router and component interface promises

As you quoted from the docs, if any of this hooks returns a Promise it will wait until its completed to move to the next one, so you can easily return a Promise that basically does nothing and wait a second (or as many time as you need). onActivate(next: ComponentInstruction, prev: ComponentInstruction) { TweenMax.fromTo($(“.title”), 1, … Read more

How do you properly promisify request?

The following should work: var request = Promise.promisify(require(“request”)); Promise.promisifyAll(request); Note that this means that request is not a free function since promisification works with prototype methods since the this isn’t known in advance. It will only work in newer versions of bluebird. Repeat it when you need to when forking the request object for cookies. … Read more

Axios interceptors and asynchronous login

Just use another promise 😀 axios.interceptors.response.use(undefined, function (err) { return new Promise(function (resolve, reject) { if (err.status === 401 && err.config && !err.config.__isRetryRequest) { serviceRefreshLogin( getRefreshToken(), success => { setTokens(success.access_token, success.refresh_token) err.config.__isRetryRequest = true err.config.headers.Authorization = ‘Bearer ‘ + getAccessToken(); axios(err.config).then(resolve, reject); }, error => { console.log(‘Refresh login error: ‘, error); reject(error); } ); } … Read more