console
async function fun0(){
console.log('fun0');
return 'returnValue';
}
fun0().then(val=>{
console.log(val)
})
async function fun1(){
console.log('fun1 Promise');
return new Promise(function(resolve,reject){
resolve('resolve Promise')
})
}
fun1().then(val => {
console.log(val);
})
console.log('----------------------------------------------');
async function fun(){
let a = await 1;
let b = await new Promise((resolve,reject)=>{
setTimeout(function(){
resolve('setTimeout')
},3000)
})
let c = await function(){
return 'function'
}()
console.log(a,b,c)
}
fun();
console.log('----------------------------------------------');
function log(time){
setTimeout(function(){
console.log(time);
return 1;
},time)
}
async function fun3(){
let a = await log(1000);
let b = await log(3000);
let c = log(2000);
console.log(a);
console.log('log')
}
fun3();
const str=async (a,b)=>{
console.log('str+a='+a+' b='+b);
return 'str';
}
console.log(str(1,2));
const start = async () => {
console.log(1)
await setTimeout(() => {
console.log(2)
}, 1000);
console.log(3);
};
start()
//async是一个加在函数前的修饰符,被async定义的函数会默认返回一个Promise对象resolve的值。
//因此对async函数可以直接then,返回值就是then方法传入的函数。