ThomasReggi
ThomasReggi

Reputation: 59425

Wrapping an async function and maintain async

I am using the node request module which is setup as follows:

request(object,function(data));

The function is a callback with the response data in it. I want to feed in a predefined set of objects, and wrap the request function in another function like so:

var quickReq(object,func){
  request(object,func);
}

quickReq({
  "method":"GET",
  "url":"http://someapi.com",
}
,function(error, response, data) {
  res.send(data);
});

Is this valid async code?

Upvotes: 0

Views: 224

Answers (2)

Pickels
Pickels

Reputation: 34630

Is this valid async code?

Yes, yes it is.

Upvotes: 2

ebohlman
ebohlman

Reputation: 15003

It's not at all clear what you're trying to do, but the first parameter to request's callback is an error code, and the second parameter is the returned content (assuming it succeeded).

Upvotes: 1

Related Questions