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 🙏

© 2026 – Pkg Stats / Ryan Hefner

async-is-fun

v0.0.3

Published

### A collection of small, composable helper functions and utilities for doing fun stuff with promises.

Readme

Async is Fun

A collection of small, composable helper functions and utilities for doing fun stuff with promises.

Installation

Node

yarn add async-is-fun
// or
npm install --save async-is-fun

Webpack

Documentation

Table of Contents

async-is-fun

defer

An overlooked pattern for Promise usage, returns An old school self contained deferred object. A fun use of this is waiting for async instantiation in class constructors.

Type: object

Properties

  • resolve function (any) resolve the Promise with value.
  • reject function (any) reject the Promise with value.
  • promise Promise

Examples

const defer = require('async-is-fun').defer

 class AsyncConstructor {
   constructor(promise){
     this.Promise = promise.promise
     setTimeout(() => {
       promise.resolve(Math.random())
     }, 1000)
   }
 }

 let later = new AsyncConstructor(defer())
 let evenLater = new AsyncConstructor(defer())

 Promise.all([later.Promise, evenLater.Promise])
 .then((results)=>{
   console.log(results) // [ 0.17888717674897858, 0.8638054083464473 ]
 })

delay

Delays resolution of a Promise by [time] amount, resolving [value]

Yes, it is true that plenty of other libraries implement this method, but is included here because it is used internally and could save someone from having to load a second bigger library like bluebird.

Parameters

Examples

const delay = require('async-is-fun').delay

Promise.resolve('Wait for it')
.then(delay(1000))
.then((result)=>{
  console.log(result) // 'wait for it'
}

Returns function (any)

retryUntil

Retry a Promise returning function

Type: function

Parameters

  • fun function A promise or value returning function, values will be wrapped in a Promise.
  • config object? The optional configuration object.
    • config.timeout object Initial timeout value before retry. (optional, default 250)
    • config.bound object Upper bound of the computed timeout. (optional, default 1000)
    • config.growth object Growth rate of the timeout per iteration. src/growIt.js (optional, default 0.2)
    • config.tries object Number of attempts before the promise is rejected. (optional, default 10)
    • config.returnErrors object Number of errors to report if [func] throws or rejects. (optional, default 5)

Examples

const retryUntil = require('async-is-fun').retryUntil

Promise.resolve({msg: 'Retry a bunch', value: 10})
.then(retryUntil((value)=>{

  //Value is passed through.
  console.log(value) // {msg: 'Retry a bunch', value: 10}

  return somePromiseReturningFun(9)
  .then((count)=>{
    console.log(count) // 9
    let total = count + value

    //If a truthy value is returned the promise will resolve with that value.
    if(total === 15){
      return {total: total}
    }

    //If we return false, the method will retry after the timout expires.
    return false
  })
}))
.then((result)=>{
  console.log(result) // {total: 19}
}

Returns function (value) Returns a Promise returning function that will resolve the first truthy value returned or resolved by the provided function. It will reject when all attempts are exhausted.