class PauseInterval {
  markerPausedLimit = 0
  timer: any = null
  start(time: number) {
    this.markerPausedLimit = time
    this.reduceStep()
  }
  reduceStep() {
    if (this.timer) {
      clearTimeout(this.timer)
      this.timer = null
    }
    this.timer = setTimeout(() => {
      this.markerPausedLimit = this.markerPausedLimit - 50 < 0 ? 0 : this.markerPausedLimit - 50
      postMessage(this.markerPausedLimit)
      this.check()
    }, 50)
  }
  check() {
    if (this.markerPausedLimit > 0) {
      this.reduceStep()
    } else {
      clearTimeout(this.timer)
      this.timer = null
    }
  }
}

const pauseInterval = new PauseInterval()

addEventListener('message', (e: any) => {
  const data = e.data as number

  pauseInterval.start(data)
})
