Skip to content

Queue where enqueued items are being sequentially dequeued based on their TTL. Head as a store value.

License

Notifications You must be signed in to change notification settings

marianmeres/ttl-queue

Repository files navigation

@marianmeres/ttl-queue

Add things to queue and have them dequeue sequentially (FIFO) based on their defined expiration (ttl). Read head of the queue as a store value.

Install

$ npm i @marianmeres/ttl-queue

Example usage

import { createTtlQueueStore } from '@marianmeres/ttl-queue';

// Using plain strings here just as an example (the enqueued value can be anything).
const q = createTtlQueueStore<string>(defaultTtl?);

// fictional example
const unsub = q.subscribe((head) => screen.show(head));

q.enqueue('one', 1_000);
q.enqueue('two', 2_000);
q.enqueue('three', 3_000);

In this example the fictional screen module above will show "one" for 1 second, then "two" for 2 seconds and then "three" for 3 seconds.

After dequeue of "three" the store value (the head) will be undefined until another q.enqueue(...) comes.

About

Queue where enqueued items are being sequentially dequeued based on their TTL. Head as a store value.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published