Skip to content

Commit 4b8577a

Browse files
committed
fix: await promise only when it is necessary
1 parent 45256b8 commit 4b8577a

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/components/Main.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,15 @@ const Main = ({
8686
do {
8787
setCurrentIndex(-1);
8888
const actions = getActions(children, splitter);
89-
await timeoutPromise(startDelay);
89+
if (startDelay > 0) await timeoutPromise(startDelay);
9090
for (const { type, payload } of actions) {
91+
if (pause) await pausePromise();
9192
if (type === 'TYPE_TOKEN') {
92-
await pausePromise();
9393
setCurrentIndex(prev => prev + 1);
9494
await timeoutPromise(typingDelay);
9595
} else if (type === 'BACKSPACE') {
9696
let amount = payload;
9797
while (amount--) {
98-
await pausePromise();
9998
setCurrentIndex(prev => prev + 1);
10099
await timeoutPromise(backspaceDelay);
101100
}
@@ -106,8 +105,8 @@ const Main = ({
106105
}
107106
}
108107
onTypingDone?.();
109-
await timeoutPromise(finishDelay);
110-
await loopPromise();
108+
if (finishDelay > 0) await timeoutPromise(finishDelay);
109+
if (!loopRef.current) await loopPromise();
111110
} while (loopRef.current);
112111
} catch (error) {
113112
// do nothing

0 commit comments

Comments
 (0)