Reputation: 1839
I'm wondering if async/await behave the same in the following two 'super-basic' examples:
async function blah1() {
return await foo.bar().then('Done');
}
as this
async function blah2() {
return blah3(foo.bar());
}
async function blah3(fn) {
return await fn.then('Done');
}
or is there some important difference?
Upvotes: 1
Views: 100
Reputation: 55729
async function blah1() {
return await foo.bar().then('Done');
}
blah1()
Calls foo.bar
, which returns a promise, to which a then
is added.
The resultant promise is returned.
async function blah2() {
return blah3(foo.bar());
}
async function blah3(fn) {
return await fn.then('Done');
}
blah2()
Calls foo.bar
, which returns a promise, which is passed to blah3
, which adds a then
.
The resultant promise is returned from blah3
to blah2
and thence to the caller.
I'd say no meaningful behavioral difference.
Upvotes: 2