A powerful library to manage your persistent timeouts!
npm i midou.ts
import { Timeouts } from "midou.ts";
const timeouts = new Timeouts({ restore: true })
(async() => {
await timeouts.add(15_000, "myCustomId", { "save": 12345 })
await timeouts.add(60_000, "otherCustomId", { "save": { "o": [1,2,3] } })
})()
timeouts.on('expires', timeout => {
console.log('Expired!', timeout)
})
timeouts.on('create', timeout => {
console.log('Created!', timeout)
})
timeouts.start() // this allow us to restore the timeouts after crash
<Timeouts>.add(ms: number, id: string, data: any): Promise<void>
<Timeouts>.remove(timeout: Timeout): Promise<void>
<Timeouts>.get_timeouts(): Promise<Timeout[]>
<Timeouts>.update_timeouts(timeouts: Timeouts[]): Promise<void>
<Timeouts>.start(): Promise<void>
{
"id": string,
"time": number,
"expires": number,
"data": any
}