<commit_before>(function (globalWorker) {
    "use strict";

    var helper;

    var DWH = function DataWorkerHelper() {
        var self = this instanceof DWH ? this : Object.create(DWH.prototype);

        self._columns     = {};
        self._rows        = [];
        self._summaryRows = [];

        self._partitionedBy   = [];
        self._partitionedRows = {};

        self._expectedNumRows;

        self._wsDatasource;
        self._wsAuthenticate;
        self._socket;

        self._cancelRequestsCmd;
        self._cancelRequestsAck;
        self._waitForCancelRequestsAck = false;
        self._onSocketClose;
        self._shouldAttemptReconnect = false;

        self._ajaxDatasource;
        self._ajaxAuthenticate;
        self._ajaxRequests = [];
        self._ajaxRequestCounter = 0;

        self._shouldClearDataset = false;

        self._rowsPerPage = 10;
        self._currentPage = undefined;

        self._onlyValidForNumbersRegex = /[^0-9.e\-]/g;

        self._hasChildElements = false;

        self._isFinished = false;

        return self;
    };

    DWH.prototype.handleMessage = function (data) {
        var self = this, reply = {};

        if (typeof(data) === "undefined") return;

        if (data.cmd === "initialize") {
            return self.initialize(data);
        } else if (data.cmd === "postMessage") {
            self._sendThroughWebSocket(data);
        } else {
            if (data.cmd in self) {
                reply = self[data.cmd](data);
            } else {
                reply["error"] = "Unrecognized DataWorker command: " + data.cmd;
            }
        }

        if (reply) self._postMessage(reply);
    };

    if (typeof(window) === "undefined") {
        // Running in WebWorker.

        DWH.prototype._postMessage = function _postMessage(reply) {
            if (!this._isFinished) globalWorker.postMessage(reply);
        };

        globalWorker.onmessage = function (e) {
            if (!helper) {
                helper = new DWH();
            }

            helper.handleMessage(e.data);
        };
    } else {
        // Running in main thread.

        // Called by DWH; DataWorker uses this to receive replies.
        DWH.prototype._postMessage = function (reply) {
            var self = this;

            setTimeout(function () {
                if (!self._isFinished) self.onmessage({ data: reply });
            });
        };

        // Called by DataWorker; DWH uses this to receive commands.
        DWH.prototype.postMessage = function () {
            var self = this,
                args = arguments;

            setTimeout(function () {
                self.handleMessage.apply(self, args);
            });
        };

        DWH.prototype.terminate = function () {
            this.onmessage = null;
        };

        window.DataWorkerHelper = DWH;
    }

    DWH.prototype.finish = function () {
        var self = this;

        if (self._socket && self._socket.readyState !== 0 && self._socket.readyState !== 3) {
            if (self._onSocketClose !== undefined) self._socket.send(self._onSocketClose);

            self._socket.onclose = function () {};
            self._socket.close();
        }

        self._postMessage({});

        self._isFinished = true;
        helper = null;
    };

    /* Initializations */

    function stringify(o) { return typeof(o) === "string" ? o : JSON.stringify(o); }

    DWH.prototype.initialize = function (data) {
        var self       = this,
            datasource = typeof(data.datasource) === "string"<commit_msg>Changed dw-helper to set isFinished after posting the message<commit_after>(function (globalWorker) {
    "use strict";

    var helper;

    var DWH = function DataWorkerHelper() {
        var self = this instanceof DWH ? this : Object.create(DWH.prototype);

        self._columns     = {};
        self._rows        = [];
        self._summaryRows = [];

        self._partitionedBy   = [];
        self._partitionedRows = {};

        self._expectedNumRows;

        self._wsDatasource;
        self._wsAuthenticate;
        self._socket;

        self._cancelRequestsCmd;
        self._cancelRequestsAck;
        self._waitForCancelRequestsAck = false;
        self._onSocketClose;
        self._shouldAttemptReconnect = false;

        self._ajaxDatasource;
        self._ajaxAuthenticate;
        self._ajaxRequests = [];
        self._ajaxRequestCounter = 0;

        self._shouldClearDataset = false;

        self._rowsPerPage = 10;
        self._currentPage = undefined;

        self._onlyValidForNumbersRegex = /[^0-9.e\-]/g;

        self._hasChildElements = false;

        self._isFinished = false;

        self._replyQueue = [];

        return self;
    };

    DWH.prototype.handleMessage = function (data) {
        var self = this, reply = {};

        if (typeof(data) === "undefined") return;

        if (data.cmd === "initialize") {
            return self.initialize(data);
        } else if (data.cmd === "postMessage") {
            self._sendThroughWebSocket(data);
        } else {
            if (data.cmd in self) {
                reply = self[data.cmd](data);
            } else {
                reply["error"] = "Unrecognized DataWorker command: " + data.cmd;
            }
        }

        if (reply) self._postMessage(reply);
    };

    if (typeof(window) === "undefined") {
        // Running in WebWorker.

        DWH.prototype._postMessage = function _postMessage(reply, finish) {
            if (!this._isFinished) {
                globalWorker.postMessage(reply);
                if (finish) this._finish();
            }
        };

        globalWorker.onmessage = function (e) {
            if (!helper) {
                helper = new DWH();
            }

            helper.handleMessage(e.data);
        };
    } else {
        // Running in main thread.

        // Called by DWH; DataWorker uses this to receive replies.
        DWH.prototype._postMessage = function (reply, finish) {
            var self = this;

            self._replyQueue.push([ reply, finish ]);

            setTimeout(function () {
                var args   = self._replyQueue.shift(),
                    reply  = args[0],
                    finish = args[1];

                if (!self._isFinished) {
                    self.onmessage({ data: reply });
                    if (finish) self._finish();
                }
            });
        };

        // Called by DataWorker; DWH uses this to receive commands.
        DWH.prototype.postMessage = function () {
            var self = this,
                args = arguments;

            setTimeout(function () {
                self.handleMessage.apply(self, args);
            });
        };

        DWH.prototype.terminate = function () {
            this.onmessage = null;
        };

        window.DataWorkerHelper = DWH;
    }

    DWH.prototype.finish = function () {
        var self = this;

        if (self._socket && self._socket.readyState !== 0 && self._socket.readyState !== 3) {
            if (self._onSocketClose !== undefined) self._socket.send(self._onSocketClose);

            self._socket.onclose = function () {};
            self._socket.close();
        }

        self._postMessage({}, true);
    };

    DWH.prototype._finish = function () {
        var self = this;

        self._isFinished = true;
        helper = null;
    };

    /* Initializations */

    function stringify(o) { return typeof(o) === "string" ? o : JSON.stringify(o); }

    DWH.prototype.initialize = function (data) {
        var self       = this,
            datasource = typeof(data.datasource) === "string"
{'fraction_non_alphanumeric': 0.11907860489328474, 'fraction_numerical': 0.002082248828735034, 'mean_word_length': 1.6814375436147941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2308515', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2026, 'n_words': 434}