New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zpromise

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zpromise

<!-- Promise简化包装器,用于增强已有Promise易用性 -->

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

特性

  • 消除Promise注入函数,直接在Promise实例上暴露resolve()和reject()即可实现状态管理

  • 提供state属性获取当前promise状态

  • 支持promise等待超时

示例

const zPromise = require('zpromise');

let promise = new zPromise()

console.log(promise.state)

setTimeout(() => {
   
   promise.resolve()

   // promise.reject()

   console.log(promise.state)

}, 1000);

超时示例

const zPromise = require('zpromise');

async function run(params) {

   let promise = new zPromise(3000)

   console.log(promise.state)
   
   await promise

   console.log(promise.state)

}

run()

API

zPromise(time)

  • time 时间,单位ms

this.state

当前promise状态,值分别为pending、resolve、reject

this.resolve()

代理Promise注入函数中的resolve,成功时执行

this.reject()

代理Promise注入函数中的reject,失败时执行

FAQs

Package last updated on 14 Aug 2018

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