I use schedule to create a class named Schedule,the code is below:
import * as schedule from "node-schedule";
import { switchStationExecuteStore } from '../controller/SwitchStation'
export class Schedule {
executionId: any;
time: any;
deviceParams:any
nodeType: any;
nodeName: any;
constructor(time,executionId,nodeName,nodeType,deviceParams) {
this.time = time
this.executionId = executionId
this.deviceParams = deviceParams
this.nodeName = nodeName
this.nodeType = nodeType
}
startJob() {
console.log(this.deviceParams.deviceId)
schedule.scheduleJob(this.time, function (executionId,nodeName,nodeType,deviceParams) {
switchStationExecuteStore[executionId].toExecuteDevice(nodeName, nodeType, deviceParams)
}.bind(null,this.executionId,this.nodeName, this.nodeType, this.deviceParams))
}
}
And in other file, I use the Schedule class,the code is
const that = this
const job = new Schedule(cornTime,this.executionId,nodeName, nodeType, deviceParams)
job.startJob()
when the code will be execte in the sametime and exectue two times with different deviceParams, the later deviceParams will overwrite the first one,so in the toExecuteDevice function I will always get the later value.
I wonder what's wrong in my code? and how can I do to fix it.Thanks so much