Skip to content

Commit

Permalink
Time Model POC, just need to work it into stage planner beat
Browse files Browse the repository at this point in the history
  • Loading branch information
REllEK-IO committed May 8, 2024
1 parent e898906 commit 2d2b361
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/model/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const handleTimedRun = (axiumState: AxiumState, func: (() => Action)[], timed: n
const timerList = timerKeys.map(t => Number(t)).sort((a, b) => a - b);
const slot = axiumState.timerLedger.get(timerList[0]);
if (slot) {
axiumState.timer.push(setTimeout(() => handleTimedRun(axiumState, slot[0], slot[1]), slot[1]));
const someTime = slot[1] - Date.now();
axiumState.timer.push(setTimeout(() => handleTimedRun(axiumState, slot[0], slot[1]), someTime >= 0 ? someTime : 0));
}
}
if (axiumState.lastRun < Date.now()) {
Expand All @@ -49,12 +50,12 @@ export const axiumTimeOut = (concepts: Concepts, func: () => Action, timeOut: nu
const slot = axiumState.timerLedger.get(timed);
if (slot) {
slot[0].push(func);
ledger.set(timed, [slot[0], timeOut]);
ledger.set(timed, [slot[0], timed]);
axiumState.timer.push(setTimeout(() => {
handleTimedRun(axiumState, slot[0], timed);
}, timeOut));
} else {
ledger.set(timed, [[func], timeOut]);
ledger.set(timed, [[func], timed]);
axiumState.timer.push(setTimeout(() => {
handleTimedRun(axiumState, [func], timed);
}, timeOut));
Expand All @@ -63,11 +64,11 @@ export const axiumTimeOut = (concepts: Concepts, func: () => Action, timeOut: nu
const slot = axiumState.timerLedger.get(timed);
if (slot) {
slot[0].push(func);
ledger.set(timed, [slot[0], timeOut]);
ledger.set(timed, [slot[0], timed]);
}
}
} else {
ledger.set(timed, [[func], timeOut]);
ledger.set(timed, [[func], timed]);
axiumState.timer.push(setTimeout(() => {
handleTimedRun(axiumState, [func], timed);
}, timeOut));
Expand Down

0 comments on commit 2d2b361

Please sign in to comment.