All files / src innet.ts

100% Statements 30/30
100% Branches 11/11
100% Functions 2/2
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44  2x   2x 2x 2x 2x 2x     38x 4x 4x 34x 4x 4x 30x 26x 26x   4x 4x       2x 38x   38x 16x   16x 38x 2x 2x 2x 2x     38x     16x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = innet;
const utils_1 = require("./utils");
let appStack = [];
let handlerStack = [];
let appStackNext = [];
let handlerStackNext = [];
let running = false;
function pushApp(app, handler, priority) {
    if (priority === 3) {
        appStackNext.push(app);
        handlerStackNext.push(handler);
    }
    else if (priority === 2) {
        appStackNext.unshift(app);
        handlerStackNext.unshift(handler);
    }
    else if (priority === 1) {
        appStack.push(app);
        handlerStack.push(handler);
    }
    else {
        appStack.unshift(app);
        handlerStack.unshift(handler);
    }
}
function innet(app, handler, priority = 1) {
    pushApp(app, handler, priority);
    if (running)
        return;
    running = true;
    while (appStack.length || appStackNext.length) {
        if (!appStack.length) {
            appStack = appStackNext;
            handlerStack = handlerStackNext;
            appStackNext = [];
            handlerStackNext = [];
        }
        (0, utils_1.runPlugins)(appStack.shift(), handlerStack.shift());
    }
    running = false;
}