Skip to content

Commit

Permalink
feat: add sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Dec 1, 2018
1 parent 3561495 commit 1f5caf0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { default as result } from './result'
export { default as sample } from './sample'
export { default as set } from './set'
export { default as shuffle } from './shuffle'
export { default as sleep } from './sleep'
export { default as startsWith } from './startsWith'
export { default as stopEventPropagation } from './stopEventPropagation'
export { default as storage } from './storage'
Expand Down
10 changes: 10 additions & 0 deletions src/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 睡眠 n 毫秒。
*
* @param milliseconds 睡眠时间,单位:毫秒
*/
export default function sleep(milliseconds: number): Promise<void> {
return new Promise(
resolve => setTimeout(resolve, milliseconds)
)
}
9 changes: 9 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,3 +1397,12 @@ describe('FileData', () => {
})
})
})

describe('sleep', () => {
test('ok', async () => {
const time1 = new Date().getTime()
await vtils.sleep(1000)
const time2 = new Date().getTime()
expect(time2 - time1 >= 1000).toBeTruthy()
})
})

0 comments on commit 1f5caf0

Please sign in to comment.