const sleep = () => {
const start = new Date().getTime();
while (new Date().getTime() - start < 5000) {
}
};
运用
const sleep = () => {
const start = new Date().getTime();
while (new Date().getTime() - start < 5000) {
}
};
const stopRecording = async () => {
iatWS.current.send(JSON.stringify({ end: true }));
sleep();// 5秒钟之后才开始运行后面的逻辑
clearWS();
};
在某个时刻取消5秒阻断
const [lastFrameEnable, setLastFrameEnable] = useState(false);
const sleep = () => {
const start = new Date().getTime();
while (new Date().getTime() - start < 5000 && lastFrameEnable === false) {
}
};
// 在某个时刻取消5秒阻断逻辑
setLastFrameEnable(true);