-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: 탭 전환 시 발생하는 타이머 오차를 Web Worker를 활용하여 사용자 경험 개선 #403
[REFACTOR] 탭 전환 시 발생하는 타이머 오차를 Web Worker를 활용하여 사용자 경험 개선
- Loading branch information
Showing
5 changed files
with
52 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default class TimerWorker { | ||
constructor(stringUrl) { | ||
this.url = stringUrl; | ||
this.onmessage = () => {}; | ||
} | ||
|
||
postMessage(message) { | ||
this.onmessage(message); | ||
} | ||
|
||
terminate() {} | ||
} | ||
|
||
// Jest 환경에서 Web Worker를 Mock으로 대체 | ||
window.Worker = TimerWorker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
frontend/src/pages/GamePage/components/SelectContainer/Timer/hooks/timerWorker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let intervalId: NodeJS.Timeout; | ||
|
||
self.onmessage = function (e) { | ||
const { type, delay } = e.data; | ||
|
||
if (type === 'start') { | ||
const startTime = Date.now(); | ||
|
||
intervalId = setInterval(() => { | ||
const elapsedTime = Date.now() - startTime; | ||
|
||
self.postMessage({ elapsedTime }); | ||
}, delay); | ||
} else if (type === 'stop') { | ||
clearInterval(intervalId); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters