🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

promise-store-js

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

promise-store-js

Create and handle Promises in a simple manner

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Promise-Store-JS

Create and handle Promises in a simple manner. Especially useful for TCP based protocol implementations.

const PromiseStore = require("promise-store-js");

const store = new PromiseStore();

store
  .create("myPromise")
  .then((res) => console.log("myPromise resolved with:", res));

store.resolve(function (el) {
  return el.context === "myPromise";
}, "Hello World");

Install

This module is available through the npm registry.

$ npm install promise-store-js

Features

  • Simple Promise creation
  • Configurable timeout
  • Resolve Promises by using custom filter functions

API

new PromiseStore([options])

Create an instance to create and handle promises.

The following table describes the properties of the optional options object.

PropertyDescriptionTypeDefault
timeoutTime in milliseconds a promise times outNumber6000

Methods

PromiseStore.create(context)

This creates a Promise and returns it.

The context argument can be of any type and is ment to be used for filtering.

PromiseStore.resolve(filter, value)

Resolve one or more Promises previously created.

The filter argument has to be a function or RegExp. In case of a function it should return a truthy to resolve the matching Promise, and a falsy value otherwise.

function (el) { return el.context === 'foo' }

In case of a RegExp, the .test() method will be called against the context, passed in while creation.

const promise = store.create('foo')
store.resolve(/foo/,'bar')
await promise // Returns 'bar'

The value argument can be of any type and will be the promise result.

Properties

PromiseStore.size

Returns the number of Promises currently pending.

Examples

https://github.com/cybusio/promise-store-js/tree/main/examples

Keywords

promise

FAQs

Package last updated on 24 Nov 2025

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