Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
/**
* Schedules repeated callbacks with an adaptive delay computed at schedule time,
* avoiding fixed 1-second polling loops when the active interval is much longer.
*/
export interface AdaptiveScheduler {
schedule: () => void;
cancel: () => void;
}
export function createAdaptiveScheduler(getDelayMs: () => number, run: () => void): AdaptiveScheduler {
let timer: ReturnType<typeof setTimeout> | null = null;
let cancelled = false;
const clear = () => {
if (timer !== null) {
clearTimeout(timer);
timer = null;
}
};
return {
schedule() {
clear();
if (cancelled) return;
timer = setTimeout(() => {
timer = null;
if (!cancelled) run();
}, Math.max(0, getDelayMs()));
},
cancel() {
cancelled = true;
clear();
},
};
}