Created
May 3, 2020 05:11
-
-
Save taulutwashi/791ec20cf31f06ed2e97a8177136b941 to your computer and use it in GitHub Desktop.
Async and await in js
This file contains 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 and Await are extensions of promises | |
// Await work under async method | |
function findAsset (page) { | |
let url = path.join(__dirname,'public',page); | |
return new Promise((resolve, reject) => { | |
fs.readFile(url,'utf-8',(err,data) => { | |
if(err) reject(err) | |
else resolve(data) | |
}); | |
}); | |
} | |
async function loadAsset(){ | |
let pageDetails = await findAsset('pagename.js'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment