4.0.0 • Published 2 years ago

timeouts.ts-dev v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

timeouts.ts-dev

Persistent timeouts that call an event when it expires using custom database!

Install

npm i timeouts.ts-dev

Usage

import { Timeouts } from "timeouts.ts-dev";

const timeouts = new Timeouts({
    pulse: 10_000, // 10 seconds,
    db: db // quickdb
})

timeouts.create('globalId', 60_000, {foo: 'bar'})

timeouts.on('expires', timeout => {
    timeout
    /**
    { id: 'globalId', time: 60000, expires: Date, data: { 'foo': 'bar' } }
    */ 
})

timeouts._init() // let's start the class

Methods

Create:

<Timeouts>.create(id: string, time: number, data: any): Promise<void>

Ex: timeouts.create('globalId', 60_000, 'hello')

Delete:

<Timeouts>.delete(func: (Timeout) => boolean): Promise<void>

Ex: timeouts.delete((timeout) => timeout.data === 'hello')

Has:

<Timeouts>.has(func: (Timeout) => boolean): Promise<boolean>

Ex: timeouts.has((timeout) => timeout.data === 'hello')

Events

ready: Timeouts
create: Timeout
delete: Timeout
expires: Timeout
4.0.0

2 years ago

3.5.0

2 years ago

3.0.0

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.0

2 years ago

1.0.5

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago