Skip to content

c-vetter/make-thenable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Make any object thenable without a fuss

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published