Skip to content

Simple way to make a request sync? #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
01AutoMonkey opened this issue Jan 28, 2017 · 1 comment
Open

Simple way to make a request sync? #75

01AutoMonkey opened this issue Jan 28, 2017 · 1 comment

Comments

@01AutoMonkey
Copy link

By default browser-request is async but I don't see any obvious way to make it sync. I have two functions, getHTTP and HTTPExists, but I also want to make getHTTPSync and HTTPExistsSync.

What are my options to make them sync?

function HTTPExists(url, cb) {
  request({ url: resolve(url), method: 'HEAD' }, function(err, res) {
    if (err) return cb(null, false);
    cb(null, /4\d\d/.test(res.statusCode) === false);
  });
}
function getHTTP(url, cb) {
  request(resolve(url), function (error, response, body) {
    if (!error && response.statusCode == 200) {
      cb(null, body);
    } else {
      cb(error, body)
    }
  })
}
@nadavye
Copy link

nadavye commented Dec 30, 2017

I think that the current API doesn't support it. Seems like it requires a minor change to the code cause as far as I was able to tell, seems like they create async requests without a way to configure it.

If you find a way around it, please drop me a line as I need that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants