mlab-speed-test
Version:
Test your download and upload speed using speed.measurementlab.net
1 lines • 1.01 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.MLabSpeedTest=void 0;const tslib_1=require("tslib"),events_1=tslib_1.__importDefault(require("events")),worker_threads_1=require("worker_threads"),path_1=tslib_1.__importDefault(require("path"));class MLabSpeedTest extends events_1.default{_running=!1;_worker;constructor(){super()}get running(){return this._running}async run(){if(!this._running)return this._running=!0,this._worker=new worker_threads_1.Worker(__dirname.endsWith("src")?path_1.default.join(__dirname,"..","lib","worker.js"):path_1.default.join(__dirname,"worker.js")),new Promise((r,n)=>{this._worker?.on("message",e=>{const t=e[0];if(this.emit(t,...e.slice(1)),t==="complete"){this._running=!1,r(e[1]);return}}),this._worker?.on("error",e=>{this.emit("error",e)}),this._worker?.on("exit",e=>{this.emit("complete",e),this._running=!1,r(e)})})}async stop(){await this._worker?.terminate(),this._worker=void 0,this._running=!1}}exports.MLabSpeedTest=MLabSpeedTest;
;