Elpho LogoElpho

scheduler module

Run delayed or repeated callbacks inside the sandbox. Use named functions only.

Overview

scheduler lets you set timeouts and intervals during a parser session. Keep callbacks short and idempotent.

Long intervals may be cut short when the session ends.

API

  • setTimeout(fn, ms), clearTimeout(id).
  • setInterval(fn, ms), clearInterval(id).

Examples

javascript
const scheduler = use("scheduler");
function ping() {
ctx.reply("Ping after delay");
}
function main() {
ctx.reply("Scheduling...");
scheduler.setTimeout(ping, 1000);
}
javascript
const scheduler = use("scheduler");
function tick() {
ctx.reply("tick");
}
function main() {
scheduler.setInterval(tick, 2000);
ctx.reply("Interval set (may stop when session ends)");
}