<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Handle asynchronous instances with async/await</title>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
function doubleAfter2seconds(num) {
return new Promise((resolve, reject) = > {
setTimeout(() = > {
resolve(2 * num)
}, 2000); })}async function timeout() {
var result = await doubleAfter2seconds(30);
return result;
}
timeout().then(result= > {
console.log(result);
})
console.log('I'll do it later, but I'll do it first.');
</script>
</body>
</html>
Copy the code