It happens often that an asynchronous function takes more than one (earlier computed) asynchronous value. With async/await, all the async function calls are done within the same function scope, exposing the values within that scope, and therefore composing those values with other asynchronous functions requires much less boiler plate.
Using a promises-only approach, or callbacks only, or something like the async library will always result in a lot more boiler plate to have access to dataString, e.g. promises-only:
function f() {
getServerData()
.then(dataString => [dataString, parseData(dataString)]), // <-- pass dataString along
.then([dataString, parsedData] => filterData(parsedData, dataString)) // <-- so you can access it here
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It happens often that an asynchronous function takes more than one (earlier computed) asynchronous value. With async/await, all the async function calls are done within the same function scope, exposing the values within that scope, and therefore composing those values with other asynchronous functions requires much less boiler plate.
Using a promises-only approach, or callbacks only, or something like the
async
library will always result in a lot more boiler plate to have access todataString
, e.g. promises-only: