npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deferrant

v1.4.0

Published

A promise exposing it's .resolve .reject. Alternative to Promise.defer.

Downloads

11

Readme

Deferrant

Non-dogmatic ultra-light Promise/defer implementation

Deferrant exists to provide a lower weight, more flexible to use alternative to defer and promise itself.

Deferrant is a Promise which exposes it's own resolve and reject methods as members. This provides an alternative to the semi-standard Deferred implementation. Additionally, unlike most promises, Deferrant exposes it's state synchronously.

Differences from promise & defer

Deferrant varies from promises in a number of key ways, usually by permitting the developer considerably more leeway with how they wish to work things.

Non-dogmatic access to state

Promises can traditionally only have their state introspected asynchronously: this forms an inherent barrier to unleashing Zalgo, in that if one needs to read a value to compute, they are forced to either a) do so asynchronously, or b) cook up a bunch of hacks to store promise state in a sychronous shadow state holding structure they stew up.

The downside of this is that all code that may touch anything asynchronous more or less has to be asynchronous, and this frequently comes with an enormous performance penalty. Rather than being able to write a piece of code that functions synchronously and fast when given synchronous data, and functions asynchronously and slowly when given asychronous data, we either have to write the code twice & take care to explicitly invoke the right method, or we take the hit of being async each and every time.

Deferrant trusts you. It exposes it's current resolved/rejected state, and the resolved or rejected value.

const d= Deferrant()
d.resolve("believe")
console.log(d.resolved) //=> believe
const d= Deferrant()
d.reject("safe")
console.log(d.rejected) //=> safe
console.log(d.fulfilled? "choice": "black iron prison")

Non-dogmatic delegation of responsibilities

Deferred's are regarded as "safe" because one can pass the promise without fear that the receiver might alter the behavior in unanticipated ways. It delegates that there is a separate promise, and a sepaarate fulfiller mechanism, and makes the two differentt.

Deferrant conjoins the two, halving the number of allocations required & reducing the number of objects one has to manage.

const d= Deferrant()
d.then(console.log) // deferrant is a promise
d.resolve("trust") // resolve called on the deferrant
//=> trust (as .then is fired)

If one wanted to create such a security barrier with Deferrant, one could wrap the deferrant in another promise: const d= Deferrant(), promise= Promise.resolve(d).