sync-async-ctor

1.0.0 • Public • Published

sync-async-ctor

A base class that serves to make an otherwise asynchronous constructor into a seemingly synchronous one.

Usage

const InitBase = require('sync-async-ctor');
 
class Database extends InitBase {
    constructor() {
        // createConnection will be initiliazed by the base class
        super(createConnection);
    }
 
    query(queryString, cb) {
        // calling init in derived methods handles queuing and ensures the asynchronous task has completed before continuing
        this.init(() => {
            this.initBase.query(queryString, cb);
        });
    }
}

Dependents (1)

Package Sidebar

Install

npm i sync-async-ctor

Weekly Downloads

9

Version

1.0.0

License

ISC

Last publish

Collaborators

  • eenewbsauce