妄想挽回 2022-05-04 13:54:13
比如重试 5 次
let time = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject("error");
}, 1000);
});
};
async function f(retry = 5) {
while (retry !== 0) {
try {
const result = await time();
return result;
} catch (e) {
if (--retry === 0) {
throw e
}
}
}
}
妄想挽回 2022-05-04 13:49:35
async function test() { const tt = await setTimeout(() => {console.log(333)}, 3000) console.log(444) console.log(tt) } test() // 444 // 562 // Promise{<resolved>: undefined} // 333
不是promise会转为promise,resolved后就继续往下执行了
async function test() {
const tt = await Promise.resolve(setTimeout(() => {console.log(333)}, 3000))
console.log(444)
console.log(tt)
}
test()
- 共 1 页
- 1
第 69 题: 如何把一个字符串的大小写取反(大写变小写小写变大写),例如 ’AbC' 变成 'aBc'