module.exports = Ready

function Ready() {
    var listeners = []
    var args

    onready.emit = onready

    return onready

    function onready(callback) {
        if (typeof callback !== "function" && listeners) {
            args = arguments
            var list = listeners
            listeners = undefined
            list.forEach(call)
            return;
        } else if (!listeners) {
            return callback && call(callback)
        }

        listeners.push(callback)
    }

    function call(cb) {
        cb.apply(null, args)
    }
}

module.exports = Ready

function Ready() {
    var ready = false
    var listeners = []
    var args

    onready.emit = onready

    return onready

    function onready(callback) {
        if (typeof callback !== "function" && !ready) {
            ready = true
            args = arguments
            listeners.forEach(call)
            return (listeners = [])
        } else if (ready) {
            return callback && call(callback)
        }

        listeners.push(callback)
    }

    function call(cb) {
        cb.apply(null, args)
    }
}

Revert "refactor to remove ready variable"
Revert "refactor to remove ready variable"

This reverts commit 75881f6adb2ac009210b2a720d6aac42628cb9fd.
