npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

jsonlee-promise

v0.0.2

Published

Enhanced adapter for promise

Downloads

17

Readme

abortPromise

简介

abortPromise 是一个用于创建带有取消功能的 Promise 的实用工具。通过将 AbortController 集成到 Promise 中,这个工具允许开发者在需要时手动取消 Promise,提供更灵活的异步任务控制。

使用方法

abortPromise 接收两个参数:

  1. executor:可以是一个 PromiseLike 对象,或一个 Executor 函数。后者在提供的 resolve 和 reject 参数上执行,来创建一个新的 Promise。
  2. controller:一个 AbortController 实例,用于在 Promise 上执行取消操作。

返回值是一个 AbortPromise,该对象是对 Promise 的代理,扩展了控制属性和方法。

代码示例

import { abortPromise } from './path-to-abortPromise';
const controller = new AbortController();

const myPromise = abortPromise((resolve, reject) => {
  setTimeout(() => resolve('任务完成'), 5000);
}, controller);

// 调用取消
myPromise.abort();

API

  • abort(): 取消 Promise 执行。
  • controller: 访问传入的 AbortController。
  • signal: 访问 AbortController 的信号对象。
  • promise: 访问创建的 Promise 对象,用于链式调用等操作。
  • then: 代理的 then 方法,允许对 Promise 继续链式调用。

英文文档:

Introduction

abortPromise is a utility for creating Promises with abort capabilities. Integrating an AbortController with a Promise, this utility lets developers manually cancel the Promise if needed, offering more control over asynchronous operations.

Usage

abortPromise takes two parameters:

  1. executor: Can be a PromiseLike object or an Executor function, which executes on provided resolve and reject arguments to create a new Promise.
  2. controller: An instance of AbortController, which can cancel the Promise operation.

The return value is an AbortPromise, a proxy of the original Promise with additional control properties and methods.

Example

import { abortPromise } from './path-to-abortPromise';
const controller = new AbortController();

const myPromise = abortPromise((resolve, reject) => {
  setTimeout(() => resolve('Task completed'), 5000);
}, controller);

// Call to abort
myPromise.abort();

API

  • abort(): Cancels the Promise execution.
  • controller: Accesses the provided AbortController.
  • signal: Accesses the signal from the AbortController.
  • promise: Accesses the underlying Promise for chaining or other operations.
  • then: A proxied then method allowing further chaining.