"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
0 && (module.exports = {
    TYPE_BUILD_OK: null,
    TYPE_BUILD_ERROR: null,
    TYPE_REFRESH: null,
    TYPE_BEFORE_REFRESH: null,
    TYPE_UNHANDLED_ERROR: null,
    TYPE_UNHANDLED_REJECTION: null,
    emit: null,
    on: null,
    off: null
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    TYPE_BUILD_OK: function() {
        return TYPE_BUILD_OK;
    },
    TYPE_BUILD_ERROR: function() {
        return TYPE_BUILD_ERROR;
    },
    TYPE_REFRESH: function() {
        return TYPE_REFRESH;
    },
    TYPE_BEFORE_REFRESH: function() {
        return TYPE_BEFORE_REFRESH;
    },
    TYPE_UNHANDLED_ERROR: function() {
        return TYPE_UNHANDLED_ERROR;
    },
    TYPE_UNHANDLED_REJECTION: function() {
        return TYPE_UNHANDLED_REJECTION;
    },
    emit: function() {
        return emit;
    },
    on: function() {
        return on;
    },
    off: function() {
        return off;
    }
});
const TYPE_BUILD_OK = "build-ok";
const TYPE_BUILD_ERROR = "build-error";
const TYPE_REFRESH = "fast-refresh";
const TYPE_BEFORE_REFRESH = "before-fast-refresh";
const TYPE_UNHANDLED_ERROR = "unhandled-error";
const TYPE_UNHANDLED_REJECTION = "unhandled-rejection";
let handlers = new Set();
let queue = [];
function drain() {
    // Draining should never happen synchronously in case multiple handlers are
    // registered.
    setTimeout(function() {
        while(// Until we are out of events:
        Boolean(queue.length) && // Or, if all handlers removed themselves as a result of handling the
        // event(s)
        Boolean(handlers.size)){
            const ev = queue.shift();
            handlers.forEach((handler)=>handler(ev));
        }
    }, 1);
}
function emit(ev) {
    queue.push(Object.freeze({
        ...ev
    }));
    drain();
}
function on(fn) {
    if (handlers.has(fn)) {
        return false;
    }
    handlers.add(fn);
    drain();
    return true;
}
function off(fn) {
    if (handlers.has(fn)) {
        handlers.delete(fn);
        return true;
    }
    return false;
}

if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  Object.defineProperty(exports.default, '__esModule', { value: true });
  Object.assign(exports.default, exports);
  module.exports = exports.default;
}

//# sourceMappingURL=bus.js.map