Socket
Socket
Sign inDemoInstall

o-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

o-promise

Open Promise 👐 — Micro tool for creating Promise likes Deferred (with AbortController support).


Version published
Weekly downloads
1K
increased by56.06%
Maintainers
1
Install size
5.36 kB
Created
Weekly downloads
 

Changelog

Source

v1.3.0

  • Canceled removing Array-methods from OpenPromise type for modern TS
  • Add readonly in OpenPromise

Readme

Source

Open Promise 👐

Micro tool for creating OpenPromise likes Deferred (with AbortController support).

npm i --save o-promise

Usage

import {createOpenPromise} from 'o-promise';

// 1. Tuple
const [promise, resolve, reject] = createOpenPromise<string>();

// 2. Deferred
const {promise, resolve, reject} = createOpenPromise<number>();

// 3. With executer + return
const open = createOpenPromise(() => {
	return '...';
});

open.state; // pending
open.reject('canceled'); // `executer` — won't be called
open.state; // rejected

// 4. With executer + promise
const open = createOpenPromise(() => {
	// for example
	return fetch('...');
});

// 5. With executer + resolvers
const open = createOpenPromise((resolve, reject) => {
	// Your Logic
});

Support AbortController

Open "fetch"
import {createOpenPromise} from 'o-promise';

const openFetch = createOpenPromise((_, __, controller) => {
	return fetch('...', {signal: controller.signal});
});

// Reject
openFetch.reject('cacneled');

// Or `AbortController#abort`
openFetch.controller.abort('canceled');

100% code & types covergae ;]

Keywords

FAQs

Last updated on 01 Apr 2024

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc