Skip to content

Commit

Permalink
feat: made jobList key named by timeframe
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Werner committed Jul 24, 2023
1 parent 9768beb commit c0b05c0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Kronos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Kronos extends EventEmitter {
constructor(){
super();

this.jobList = [];
this.jobList = {};
}
subscribe(timeframe){
let cronRule;
Expand Down Expand Up @@ -47,15 +47,17 @@ class Kronos extends EventEmitter {
const start = false;
const utcOffset = moment().utcOffset();
const job = new CronJob(cronRule, onTick, onComplete, start, null, null, null, utcOffset);
this.jobList.push(job);
job.start();
if(!this.jobList[timeframe]){
this.jobList[timeframe] = job;
}
this.jobList[timeframe].start();
this.emit('SUBSCRIPTIONS', {type:'SUBSCRIBED', payload:{timeframe}});
}
unsubscribeAll(){
this.jobList.forEach((job)=>{
Object.entries(this.jobList).forEach(([,job])=>{
job.stop();
});
this.jobList = [];
this.jobList = {};
}
};
module.exports = Kronos;

0 comments on commit c0b05c0

Please sign in to comment.