Skip to content

zhangfisher/asyncsignal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AsyncSignal

Reusable asynchronous signals

中文

Installation

pnpm add asyncsignal
// or 
npm install asyncsignal
// or 
yarn add asyncsignal

Usage

import { asyncSignal } from 'asyncsignal';

// Create a signal/Promise
const signal = asyncSignal();
// or with a constraint
// when the resolve is executed, the constraint function must return true
const signal = asyncSignal(()=>true);
// or with options
const signal = asyncSignal(()=>true,{timeout:100});

// wait signal is resolved
await signal()
// wait signal is resolved with a timeout
await signal(100)
// wait signal is resolved with a timeout and throw error
await signal(100,new Error())  
  

signal.resolve('resolved value')
// or
signal.reject('rejected value') 
signal.reject(new Error('rejected error'))

// check signal status
signal.isPending() 
signal.isResolved()
signal.isRejected()

// reset signal
signal.reset() 

Open Source Projects

Releases

No releases published

Packages

No packages published