const logger = require('../kit/logger-kit') module.exports = class Task { constructor(context, delayTime, initFun, onTickFun) { this.context = context this.delayTime = delayTime this.init = initFun this.onTick = onTickFun } async Start() { const task = this await this.init() this.interval = setInterval(() => { try { task.onTick(task.context) } catch (e) { logger.error(e) } }, this.delayTime) } async Stop() { clearInterval(this.interval) } }