Comparing version 1.0.0-beta.7 to 1.0.0-beta.8
"use strict"; | ||
// tslint:disable max-classes-per-file | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const get_bundle_url_browser_1 = require("./get-bundle-url.browser"); | ||
const defaultPoolSize = navigator.hardwareConcurrency || 4; | ||
const isAbsoluteURL = (value) => /^(https?:)?\/\//i.test(value); | ||
const isAbsoluteURL = (value) => /^(file|https?:)?\/\//i.test(value); | ||
function createSourceBlobURL(code) { | ||
@@ -10,2 +12,11 @@ const blob = new Blob([code], { type: "application/javascript" }); | ||
function selectWorkerImplementation() { | ||
if (typeof Worker === "undefined") { | ||
// Might happen on Safari, for instance | ||
// The idea is to only fail if the constructor is actually used | ||
return class NoWebWorker { | ||
constructor() { | ||
throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers."); | ||
} | ||
}; | ||
} | ||
return class WebWorker extends Worker { | ||
@@ -16,2 +27,6 @@ constructor(url, options) { | ||
} | ||
else if (typeof url === "string" && !isAbsoluteURL(url) && get_bundle_url_browser_1.getBundleURL().match(/^file:\/\//i)) { | ||
url = new URL(url, get_bundle_url_browser_1.getBundleURL().replace(/\/[^\/]+$/, "/")); | ||
url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`); | ||
} | ||
if (typeof url === "string" && isAbsoluteURL(url)) { | ||
@@ -18,0 +33,0 @@ // Create source code blob loading JS file via `importScripts()` |
@@ -63,3 +63,3 @@ "use strict"; | ||
const { payload, transferables } = deconstructTransfer(resultValue); | ||
const startMessage = { | ||
const resultMessage = { | ||
type: messages_1.WorkerMessageType.result, | ||
@@ -70,3 +70,3 @@ uid, | ||
}; | ||
implementation_1.default.postMessageToMaster(startMessage, transferables); | ||
implementation_1.default.postMessageToMaster(resultMessage, transferables); | ||
} | ||
@@ -153,3 +153,3 @@ function postJobStartMessage(uid, resultType) { | ||
// Post with some delay, so the master had some time to subscribe to messages | ||
setTimeout(() => postUncaughtErrorMessage(event.error), 250); | ||
setTimeout(() => postUncaughtErrorMessage(event.error || event), 250); | ||
}); | ||
@@ -156,0 +156,0 @@ self.addEventListener("unhandledrejection", event => { |
{ | ||
"name": "threads", | ||
"version": "1.0.0-beta.7", | ||
"version": "1.0.0-beta.8", | ||
"description": "Easy to use, yet powerful multi-threading library for node.js, web browsers and Electron", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86082
62
1862