L
L
lex2018-09-28 09:27:21
Node.js
lex, 2018-09-28 09:27:21

Asynchronous request and promises?

Good afternoon! Please tell me where am I wrong? why is the promise empty, well, as if the result is not waiting.

let dfd = vow.defer();

const options = {
    url: 'http://www.part-kom.ru/engine/api/v3/search/parts',
    headers: {
        'Authorization': 'Basic ' + login,
        'Accept': 'application/json',
        'Content-type': 'application/json'
    },
    qs: { number: '1111' },
    json: true
};

rp(options)
    .then(result => {
        dfd.resolve(result);
    });

return dfd.promise();

part of the code, but the point is that if you wait for the result in console.log, then sooner or later it will come, why is it not passed to resolve for further work? I also tried to resolve the data synchronously on the data event, but the essence of the problem is the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2018-09-28
bem @bemdev

apparently rp (options) return the promise and so - why such difficulties?
return rp(options)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question