
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
async-inheritance
Advanced tools
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.
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
})()
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)This module requires the following features:
SymbolPromiseasync/awaitconstObject.getPrototypeOfObject.getOwnPropertyNamesObject.getOwnPropertySymbolsFAQs
Provide async constructor functionality to JavaScript classes
We found that async-inheritance 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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.