1. faked-promise
Create a promise that can be resolved and rejected outside of it
faked-promise
Package: faked-promise
Created by: posva
Last modified: Mon, 02 May 2022 03:17:09 GMT
Version: 2.2.2
License: MIT
Downloads: 487
Repository: https://github.com/posva/faked-promise

Install

npm install faked-promise
yarn add faked-promise

faked-promise Build Status npm package coverage thanks

Create a promise that can be resolved and rejected programatically outside of it

It basically extracts the resolve and reject callbacks so you can call them whenever you need.
⚠️ The promise can only be resolved once, it's still a regular Promise after all.

Installation

 npm i faked-promise

Usage

faked-promise exports one single function that takes no arguments and returns an array with 3 elements:

  • A real promise
  • Its resolve callback
  • Its reject callback

Meaning you can control exactly when the promise is resolved or rejected:

 const fakePromise = require('faked-promise')

const [promise, resolve, reject] = fakePromise()
promise.then(() => {})
resolve('any value')

License

MIT

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code