1.0.0 • Published 7 years ago

sync-async-ctor v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

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);
        });
    }
}