Home Function enters then before request completed
Reply: 0

Function enters then before request completed

user1094
1#
user1094 Published in June 23, 2018, 8:01 am

My async function enters then before request is completed. Shouldn't Then part of the code executes only after the async function is completed? How to make the function call only when all the function has finished executing?

app.js

var request_test = require('./request_test');

baseUrl = "https://github.com";
promiseFunction().then((result)=>{
    console.log("complete")
});

var promiseFunction = async function promiseFunction() {
    request_test.request_test(baseUrl);
}

request_test.js

var request = require('request');
var cheerio = require('cheerio');

var request_test = function check(baseUrl) {
    console.log("baseUrl:" + baseUrl)
     var options = {
        url: baseUrl
     };
     request(options, function (error, response, html) {
        if (!error) {
           console.log("no error");
        }else{
        console.log("else js");
        console.log(error);
        }
      });
 }

module.exports = {
    request_test: request_test
};

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307191 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO