var sleep = function (time) { return new Promise(function (resolve, reject) { setTimeout(function () { //此处执行异步操作 resolve(‘ok‘); }, time); }); }; var start = async function () { try{ console.log(‘start‘); var result = await sleep(1000); console.log(result); console.log(‘end‘); }catch(err){ console.log(err); } }; start();
时间: 2024-10-07 02:23:49