Socket
Socket
Sign inDemoInstall

make-thenable

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    make-thenable

Make any object thenable without a fuss


Version published
Weekly downloads
4
Maintainers
1
Install size
5.59 kB
Created
Weekly downloads
 

Readme

Source

make-thenable

Make an object thenable without a fuss

What it does

const makeThenable = require('make-thenable')

const promiseLike = {}

const [resolve, reject] = makeThenable(promiseLike)

Now, the given object behaves exactly like a good little Promise: you can add callbacks through promiseLike.then and promiseLike.catch, and resolve/reject through the return values. That is because it is now linked to a real Promise. Consequently, in Internet Explorer, you need a polyfill.

Also resolvable

const makeThenable = require('make-thenable/resolvable')

const promiseLike = makeThenable({})

This gives you the same functionality as above, plus promiseLike.resolve and promiseLike.reject.

Why it exists

Sometimes, you need an arbitrary object to behave like a Promise. In times like these, just make it thenable and be happy.

After writing the original version, I came across an article by Lea Verou, and thought I'd cover her use-case as well. That's why there's make-thenable/resolvable

Keywords

FAQs

Last updated on 13 Feb 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc