async/await 运用示例

129 阅读1分钟
async function one() {
	console.log(1)
	let a = await two()
	console.log('a', a)
	console.log(3)
}

function two() {
	setTimeout(()=>{
		console.log(2)
		return 2
	},1000)
}

one()

打印顺序 :
1
2
'a' 2
3