Skip to content

Instantly share code, notes, and snippets.

@jackyshan jackyshan/promise.js
Created Dec 28, 2018

Embed
What would you like to do?
js实现promise,async,await
// async function helloAsync(){
// return "helloAsync";
// }
// console.log(helloAsync()) // Promise {<resolved>: "helloAsync"}
// helloAsync().then(v=>{
// console.log(v); // helloAsync
// })
function testAwait(){
return new Promise((resolve) => {
setTimeout(function(){
console.log("testAwait");
resolve('aaaa');
}, 1000);
});
}
async function helloAsync(){
return await Promise.resolve('dddd')
// await testAwait();
// console.log(c)
// console.log("helloAsync");
}
helloAsync().then((data)=>{
console.log(data)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.