
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
tiny-thenable
Advanced tools
This is a lightweight thenable implementation in JavaScript. It is entirely self-contained within a single function with no external dependencies, so it can be easily serialized to a web worker, for example.
This implementation conforms fully to the Promises/A+ spec, so it can safely interoperate with other thenable implementations.
However, it is not a full implementation of ES2015 Promises, e.g. it does not have the same constructor signature and does not expose a catch
method or the static resolve
/reject
/all
/race
initializer methods. If you need to hand a Thenable instance off to consuming code that may expect a true Promise, you'll want to wrap it in a native-or-polyfilled Promise first.
Why yet another Promises/A+ implementation? Great question. We needed a polyfill-like thing that was (a) wrapped in a single function for easy serialization across to a Worker, and (b) was as small as possible -- at ~900B minified (~500B gzipped) this is the smallest implementation I found at the time. And also, exercises like this are challenging and fun!
This began as a utility in troika-worker-utils as a way to use Promise
-like objects in web workers where the browser may not have a native Promise
implementation. The browser support landscape changed since such that native Promises can now be used reliably in that project, so this JS implementation has been extracted and placed here for posterity and for anyone else who might need such a thing.
npm install tiny-thenable
import Thenable from 'tiny-thenable'
const myThenable = Thenable()
myThenable.then(
result => {
console.log('Got result: ' + result)
},
error => {
console.error(error)
}
)
myThenable.resolve('OK!')
// or: myThenable.reject(new Error('Oopsie!'))
Since it has a then()
method, it should be usable as
There's also a Thenable.all([...thenables])
utility function that behaves like Promise.all()
.
FAQs
A small JavaScript implementation of Promises/A+ thenables
The npm package tiny-thenable receives a total of 0 weekly downloads. As such, tiny-thenable popularity was classified as not popular.
We found that tiny-thenable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.