Promise 对象可以将异步操作转换成同步操作,setTimeout 用于延迟执行一个函数。
const waitTime = (milliscond) => {
return new Promise(resolve => setTimeout(resolve, milliscond));
};
console.log("start")
await waitTime(5000);
console.log("end after 5 seconds, done!")
Promise 对象可以将异步操作转换成同步操作,setTimeout 用于延迟执行一个函数。
const waitTime = (milliscond) => {
return new Promise(resolve => setTimeout(resolve, milliscond));
};
console.log("start")
await waitTime(5000);
console.log("end after 5 seconds, done!")