Created
May 30, 2025 14:29
-
-
Save sunmeat/487e4c073fb285036a55827d168e6d06 to your computer and use it in GitHub Desktop.
что есть асинхронная функция на самом деле
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
когда говорят, что функция "оборачивается в промис", имеют в виду, что при использовании async функция автоматически возвращает промис, | |
даже если внутри просто возвращается значение. это синтаксический сахар над использованием конструктора Promise. | |
такой код: | |
async function bar() { | |
const result = await someAsyncFunction(); | |
return result + 1; | |
} | |
на самом деле разворачивается в это: | |
function bar() { | |
return someAsyncFunction().then(result => result + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment