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-inheritance

v1.0.0

Published

Provide async constructor functionality to JavaScript classes

Readme

async-inheritance

This module provides a class and the symbols necessary to create classes whose constructors return promises, while staying as close to JavaScript's normal class inheritance functionality as possible.

Usage

The simplest async class looks like this:

const {AsyncClass, async_constructor, async_super} = require("async-inheritance")

class MyClass extends AsyncClass {
    async [async_constructor]() {
        await this[async_super]()
        // async code
    }
}

(async () => {
    const instance = await new MyClass()
    console.log(instance instanceof MyClass) // true
})()

Classes that extend AsyncClass can then be extended further:

const {AsyncClass, async_constructor, async_super} = require("async-inheritance")
const timers = require("timers/promises")

class MyClass1 extends AsyncClass {
    async [async_constructor](construction_delay) {
        await this[async_super]()
        await timers.setTimeout(construction_delay)
    }
}

class MyClass2 extends MyClass1 {
    async [async_constructor]() {
        await this[async_super](100)
        console.log("Finished constructor")
    }
}

(async () => {
    await new MyClass2()
})()

If a child class overrides [[async_constructor]] it must call [[async_super]], but the constructor can be omitted entirely with no issue:

const {AsyncClass, async_constructor, async_super} = require("async-inheritance")
const timers = require("timers/promises")

class MyClass1 extends AsyncClass {
    async [async_constructor](construction_delay) {
        await this[async_super]()
        await timers.setTimeout(construction_delay)
    }
    do_something() {
        // do something
    }
}

class MyClass2 extends MyClass1 {
    do_something() {
        super.do_something()
        // do something more
    }
}

class MyClass3 extends MyClass2 {
    async [async_constructor]() {
        await this[async_super](100)
        console.log("Finished constructor")
    }
}

(async () => {
    await new MyClass3()
})()

Just like with normal constructors, the async constructor can return an object:

const {AsyncClass, async_constructor, async_super} = require("async-inheritance")

class MyClass extends AsyncClass {
    async [async_constructor]() {
        await this[async_super]()
        return {my_property: 1}
    }
}

(async () => {
    const instance = await new MyClass()
    console.log(instance.my_property === 1) // true
})()

Notes

  • Overriding the normal constructor will break the async constructor's functionality
  • Acessing this before calling await this[async_super]() may cause unexpected behavior (it does NOT throw an error the way that normal JavaScript class inheritance does)

Compatibility

This module requires the following features:

  • Symbol
  • Promise
  • classes
  • async/await
  • const
  • rest/spread operator
  • generator functions
  • Object.getPrototypeOf
  • Object.getOwnPropertyNames
  • Object.getOwnPropertySymbols