Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

disk-queue

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disk-queue

A queue persist on filesytem to save memory

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

disk-queue

A queue persist on filesytem to save memory

Install

$ npm install disk-queue
# or
$ pnpm add disk-queue

Usage

import { DiskQueue } from "disk-queue";
const queue = new DiskQueue({
  filePath,
});
queue.push({ data: 1 });
console.log(queue.remainCount); // 1
queue.push(...[{ data: 2 }, { data: 3 }]);
console.log(queue.remainCount); // 3

console.log(queue.shift()); // {data: 1}
console.log(queue.remainCount); // 2

//...
if (queue.remainCount === 0) {
  console.log(queue.shift()); // undefined
}

API

DiskQueue(options)

class of disk queue recive a options object

options

Type:

interface Options {
    filePath: string; // filePath to persist queue
    serializer?: Serializer; // default is JSON.stringify
    deserializer?: DeSerializer; // default is JSON.parse
}

push(data: unknown)

add items to queue work like Array#shift

shift(): unknown|undefined

dequeue a item work like Array#shift

reset()

discard jobs and reset everything

close()

close internal file descriptor, push after close will throw fd error

queue.remainCount

The number of remaining item in queue

queue#drain

event triggered when queue remainCount hit zero

queue.on('drain', () => {
    assert(queue.remainCount === 0)
})

queue#reset

event triggered when queue.reset is called

Keywords

FAQs

Package last updated on 08 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc