-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(utils): delay 함수 추가 * fix: delay 함수 관련 문서 내에 존재하는 불필요한 함수 수정 완료 * Create long-lobsters-type.md * fix: 테스트코드 동작시간 단축을 위한 delay함수 검증시간 수정 완료 * refac: useBlockPromiseMultipleClick 테스트코드에서 사용중인 delay함수를 utils에 있는 함수로 교체 완료 --------- Co-authored-by: Gromit (전민재) <[email protected]>
- Loading branch information
Showing
6 changed files
with
52 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@modern-kit/utils": patch | ||
--- | ||
|
||
feat(utils): delay 함수 추가 |
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,24 @@ | ||
# delay | ||
|
||
주어진 시간만큼 기다린 뒤 다음 동작을 수행할 수 있도록 하는 함수입니다. | ||
|
||
setTimeout을 사용하여 특정 시간 뒤의 동작을 정의할 경우, 해당 시간 뒤 동작해야하는 함수 다음에 Promise가 존재한다면 setTimeout은 macroTaskQueue에 속하고 Promise는 microTaskQueue에 속하게 되어 의도한 바와 같이 순서대로의 동작을 보장하지 못할 수 있습니다. delay 함수를 사용한다면 이러한 문제를 해결할 수 있습니다. | ||
|
||
<br /> | ||
|
||
## Interface | ||
```tsx | ||
const delay: (time: number) => Promise<void> | ||
``` | ||
## Usage | ||
```ts | ||
import { delay } from '@modern-kit/utils'; | ||
|
||
const something = () => Promise.resolve() | ||
|
||
const doSomethingAfterDelay = async () => { | ||
await delay(1000) | ||
await something() | ||
} | ||
``` |
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 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { delay } from '.'; | ||
|
||
describe('delay', () => { | ||
it('should delay the promise by the given time', async () => { | ||
const time = 200; | ||
const start = Date.now(); | ||
|
||
await delay(time); | ||
|
||
const end = Date.now(); | ||
|
||
expect(end - start).toBeGreaterThanOrEqual(time); | ||
}); | ||
}); |
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,5 @@ | ||
export const delay = (time: number) => { | ||
return new Promise<void>((resolve) => { | ||
setTimeout(() => resolve(), time); | ||
}); | ||
}; |
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