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

defer-map

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defer-map

A small Map wrapper with defer and expiry.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version CI Dependency Status Dev Dependency Status Codecov

Defer Map

A small Map wrapper with defer and expiry.

Table of Contents

Features

  • 💥 Configure expiry to auto remove items.
  • 🐙 Uses promises to defer values.
  • 🚀 Drop in replacement for native Map.
  • 💪 Written in TypeScript.

Installation

npm install defer-map --save

Usage

import { DeferMap } from 'defer-map';

const expiry = 60 * 60 * 1000; // 1 hours
const map = new DeferMap({ expiry });

map.set('hero', 'Luke Skywalker');
const deferred = map.defer('villain');

console.log(map.size);
// => 2

console.log(await map.get('hero').result);
// => Luke Skywalker

deferred.done('Darth Vadar');

console.log(await map.get('villain').result);
// => Darth Vadar

// ... 1 hour later ....

console.log(map.get('hero'), map.get('villain'));
// => undefined, undefined

The defer-map API follows the native JS Map, with a few key additions.

The constructor (new DeferMap()) takes an optional configuration object with the following properties:

PropertyTypeDescriptionDefault
expirynumberNumber of milliseconds before items will expire.n/a

If expiry is set, expired items are not instantly removed. If you call get with a key for an expired item, it will be removed and undefined will be returned. Alternatively, you can call cleanup to remove all expired items.

The get method returns an object, instead of the set value directly. The result property on the object returned by get is a Promise that is resolved with the set value.

Development

npm install
npm run build

Keywords

FAQs

Package last updated on 29 Oct 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