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

promise-faker

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-faker

Provides promise-like APIs but runs synchronously. This module is useful for controlling flows.

  • 1.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage

promise-faker

Provides Promise-like APIs but runs synchronously. This module is useful for controlling flows.

Install

$ npm install promise-faker

Usage

import FakePromise from 'promise-faker'

// Write flows as normal Promise does
function factory (p) {
  const result = p.resolve(1)
  .then(() => {
    return 2
  })

  // Not to make the following chain.
  return p.resolve(result, true)
}

// Then, run them as synchronous flows
factory(FakePromise)  // 2
factory(Promise)      // Promise {2}

FakePromise actually runs synchronously:

Promise.resolve(1).then(console.log)
console.log(2)
// 2
// 1

FakePromise.resolve(3).then(console.log)
console.log(4)
// 3
// 4

new FakePromise(executor)

  • executor Function(resolve, reject)

Returns a fake promise

FakePromise.resolve(subject [, end])

  • end ?boolean=false The additional parameter only for FakePromise, and if this parameter is true, it will try to get the final value or throw an error if there is a rejection.
FakePromise.resolve(FakePromise.resolve(1), true)
// 1

FakePromise.resolve(FakePromise.reject('2'), true)
// -> throw '2'

And if the fake promise is still pending, an Error('pending unexpectedly') error will thrown.

const p = new FakePromise((resolve, reject) => {
  return 1
})

try {
  FakePromise.resolve(p, true)
} catch (e) {
  console.log(e.message)  // 'pending unexpectedly'
}

FakePromise.reject(subject)

Similar as Promise.reject, but returns a fake promise

FakePromise.all(tasks)

Similar as Promise.all, but returns a fake promise

promise.then(onResolve [, onReject])

Similar as promise.then, but returns a fake promise

promise.catch(onReject)

Similar as promise.catch, but returns a fake promise

await

The FakePromise instance could even be awaited

console.log(await FakePromise.resolve(1))  // 1

await FakePromise.reject('error') // throw 'error'

License

MIT

Keywords

FAQs

Package last updated on 22 Feb 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