#45 : Promisify
This commit is contained in:
@@ -17,25 +17,28 @@ export class ProgressManager {
|
||||
}
|
||||
|
||||
start(onFinish) {
|
||||
this.reset()
|
||||
return new Promise((resolve) => {
|
||||
this.reset()
|
||||
|
||||
const stepMs = Math.min(STEP_MS, this.#autoplayDuration)
|
||||
let progress = -stepMs
|
||||
|
||||
this.#interval = setIntervalImmediate(() => {
|
||||
if (this.#paused) {
|
||||
return
|
||||
}
|
||||
progress += stepMs
|
||||
|
||||
const value = progress / this.#autoplayDuration
|
||||
this.#onProgressValueChange(value)
|
||||
|
||||
if (value > 1) {
|
||||
this.reset()
|
||||
onFinish()
|
||||
}
|
||||
}, stepMs)
|
||||
const stepMs = Math.min(STEP_MS, this.#autoplayDuration)
|
||||
let progress = -stepMs
|
||||
|
||||
this.#interval = setIntervalImmediate(async () => {
|
||||
if (this.#paused) {
|
||||
return
|
||||
}
|
||||
progress += stepMs
|
||||
|
||||
const value = progress / this.#autoplayDuration
|
||||
this.#onProgressValueChange(value)
|
||||
|
||||
if (value > 1) {
|
||||
this.reset()
|
||||
await onFinish()
|
||||
resolve()
|
||||
}
|
||||
}, stepMs)
|
||||
})
|
||||
}
|
||||
|
||||
pause() {
|
||||
|
||||
@@ -2,3 +2,11 @@ export const setIntervalImmediate = (fn, ms) => {
|
||||
fn();
|
||||
return setInterval(fn, ms);
|
||||
}
|
||||
|
||||
export const wait = (ms) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
}, ms)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user