In the package Super Agent, the docs state:
A request can be initiated by invoking the appropriate method on the request object, then calling .then() (or .end() or await) to send the request.
request
.get('/search')
.then(res => {
// res.body, res.headers, res.status
});
However SuperAgent supports method chaining such as
request.get('/search')
.set('header1','value')
.set('header2','value')
to modify the request before it is sent. So...
How does the request object know when the method chain is finished so it doesn't prematurely send?
My theory is that any chain off of the request
object returns a thenable object which is able to be await
'd or .then()
'd, and when it is, it will fire off a request and return an actual promise.
I looked around in the superagent repo and couldn't find anything like that. How else might waiting to send the request until the method chain is complete be accomplished?