midou.ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

midou.ts

A powerful library to manage your persistent timeouts!

Table of content

Install

npm i midou.ts

Example:

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

Functions

<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>

Interfaces

Timeout

{
    "id": string,
    "time": number,
    "expires": number,
    "data": any
}

Package Sidebar

Install

npm i midou.ts

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

5.89 kB

Total Files

5

Last publish

Collaborators

  • midowo