K
K
krlljs2017-09-06 18:50:48
JavaScript
krlljs, 2017-09-06 18:50:48

I am writing a wrapper for the request module so that it returns a value using promise and async / await, where did I go wrong?

var request = require('request');

console.log((async function(){
  return await new Promise(function(res,rej){
    request('http://toster.ru', function(e,r){
      if(e) rej(e);
      else res(r);
    });
  });  
})());

C:\>node test
Promise { <pending> }

It seems that he did everything right, he did it a hundred times before about four months ago, where did he go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2017-09-06
@healqq

var request = require('request');
(async function() {
    console.log(await new Promise(
        function(res,rej){
            request('http://toster.ru', function(e,r) {
                if(e) rej(e);
                else res(r);
            });
        }));
})();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question