troika-worker-utils
Advanced tools
Comparing version 0.26.0 to 0.26.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.26.1](https://github.com/protectwise/troika/compare/v0.26.0...v0.26.1) (2020-05-26) | ||
### Bug Fixes | ||
* **troika-worker-modules:** silence fallback warning in non-browser environments ([3dedb8f](https://github.com/protectwise/troika/commit/3dedb8f2b338e9345c107831863152b115ca50d2)) | ||
# [0.26.0](https://github.com/protectwise/troika/compare/v0.25.0...v0.26.0) (2020-05-24) | ||
@@ -8,0 +19,0 @@ |
@@ -380,2 +380,28 @@ /** | ||
let supportsWorkers = () => { | ||
let supported = false; | ||
// Only attempt worker initialization in browsers; elsewhere it would just be | ||
// noise e.g. loading into a Node environment for SSR. | ||
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { | ||
try { | ||
// TODO additional checks for things like importScripts within the worker? | ||
// Would need to be an async check. | ||
let worker = new Worker( | ||
URL.createObjectURL( | ||
new Blob([''], { type: 'application/javascript' }) | ||
) | ||
); | ||
worker.terminate(); | ||
supported = true; | ||
} catch (err) { | ||
console.warn(`Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [${err.message}]`); | ||
} | ||
} | ||
// Cached result | ||
supportsWorkers = () => supported; | ||
return supported | ||
}; | ||
let _workerModuleId = 0; | ||
@@ -388,20 +414,2 @@ let _messageId = 0; | ||
let supportsWorkers = () => { | ||
let supported = false; | ||
try { | ||
// TODO additional checks for things like importScripts within the worker? | ||
// Would need to be an async check. | ||
let worker = new Worker( | ||
URL.createObjectURL( | ||
new Blob([''], {type: 'application/javascript'}) | ||
) | ||
); | ||
worker.terminate(); | ||
supported = true; | ||
} catch(err) { | ||
console.warn(`Troika createWorkerModule: web workers not allowed in current environment; falling back to main thread execution.`, err); | ||
} | ||
supportsWorkers = () => supported; | ||
return supported | ||
}; | ||
@@ -408,0 +416,0 @@ /** |
@@ -405,2 +405,28 @@ (function (global, factory) { | ||
var supportsWorkers = function () { | ||
var supported = false; | ||
// Only attempt worker initialization in browsers; elsewhere it would just be | ||
// noise e.g. loading into a Node environment for SSR. | ||
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { | ||
try { | ||
// TODO additional checks for things like importScripts within the worker? | ||
// Would need to be an async check. | ||
var worker = new Worker( | ||
URL.createObjectURL( | ||
new Blob([''], { type: 'application/javascript' }) | ||
) | ||
); | ||
worker.terminate(); | ||
supported = true; | ||
} catch (err) { | ||
console.warn(("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + (err.message) + "]")); | ||
} | ||
} | ||
// Cached result | ||
supportsWorkers = function () { return supported; }; | ||
return supported | ||
}; | ||
var _workerModuleId = 0; | ||
@@ -413,20 +439,2 @@ var _messageId = 0; | ||
var supportsWorkers = function () { | ||
var supported = false; | ||
try { | ||
// TODO additional checks for things like importScripts within the worker? | ||
// Would need to be an async check. | ||
var worker = new Worker( | ||
URL.createObjectURL( | ||
new Blob([''], {type: 'application/javascript'}) | ||
) | ||
); | ||
worker.terminate(); | ||
supported = true; | ||
} catch(err) { | ||
console.warn("Troika createWorkerModule: web workers not allowed in current environment; falling back to main thread execution.", err); | ||
} | ||
supportsWorkers = function () { return supported; }; | ||
return supported | ||
}; | ||
@@ -433,0 +441,0 @@ /** |
@@ -11,3 +11,3 @@ 'use strict';(function(m,r){"object"===typeof exports&&"undefined"!==typeof module?r(exports):"function"===typeof define&&define.amd?define(["exports"],r):(m=m||self,r(m.troika_worker_utils={}))})(this,function(m){function r(){function c(f,b){p++;var v=0;try{b===q&&g();var u=0<f&&e(b);u?u.call(b,a(function(a){v++;c(1,a)}),a(function(a){v++;c(-1,a)})):(l=f,k=b,h||(setTimeout(d,0),h=1))}catch(D){l||v||c(-1,D)}}function d(){var a=f;h=0;f=[];a.forEach(b)}function b(a){a()}function e(a){a=a&&(n(a)||"object"=== | ||
/^\w+\s*\(/.test(c)&&(c="function "+c);return c}function I(c){var d=C[c];d||(d=t(F),d=C[c]=new Worker(URL.createObjectURL(new Blob(["/** Worker Module Bootstrap: "+c.replace(/\*/g,"")+" **/\n\n;("+d+")()"],{type:"application/javascript"}))),d.onmessage=function(b){b=b.data;var c=b.messageId,a=n[c];if(!a)throw Error("WorkerModule response with empty or unknown messageId");delete n[c];n.count--;a(b)});return d}function A(c,d,b){var e=q(),a=++J;n[a]=function(a){a.success?e.resolve(a.result):e.reject(Error("Error in worker "+ | ||
d+" call: "+a.error))};n._count++;1E3<n.count&&console.warn("Large number of open WorkerModule requests, some may not be returning");I(c).postMessage({messageId:a,action:d,data:b});return e}r.all=z.all=function(c){var d=0,b=[],e=q();0===c.length?e.resolve([]):c.forEach(function(a,g){var l=q();l.resolve(a);l.then(function(a){d++;b[g]=a;d===c.length&&e.resolve(b)},e.reject)});return e};var q="function"===typeof Promise?z:r,H=0,J=0,x=!1,C=Object.create(null),n=Object.create(null);n._count=0;var B=function(){var c= | ||
!1;try{(new Worker(URL.createObjectURL(new Blob([""],{type:"application/javascript"})))).terminate(),c=!0}catch(d){console.warn("Troika createWorkerModule: web workers not allowed in current environment; falling back to main thread execution.",d)}B=function(){return c};return c},K=w({name:"Thenable",dependencies:[q],init:function(c){return c}});m.Thenable=q;m.ThenableWorkerModule=K;m.defineWorkerModule=w;m.stringifyFunction=t;Object.defineProperty(m,"__esModule",{value:!0})}) | ||
d+" call: "+a.error))};n._count++;1E3<n.count&&console.warn("Large number of open WorkerModule requests, some may not be returning");I(c).postMessage({messageId:a,action:d,data:b});return e}r.all=z.all=function(c){var d=0,b=[],e=q();0===c.length?e.resolve([]):c.forEach(function(a,g){var l=q();l.resolve(a);l.then(function(a){d++;b[g]=a;d===c.length&&e.resolve(b)},e.reject)});return e};var q="function"===typeof Promise?z:r,B=function(){var c=!1;if("undefined"!==typeof window&&"undefined"!==typeof window.document)try{(new Worker(URL.createObjectURL(new Blob([""], | ||
{type:"application/javascript"})))).terminate(),c=!0}catch(d){console.warn("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: ["+d.message+"]")}B=function(){return c};return c},H=0,J=0,x=!1,C=Object.create(null),n=Object.create(null);n._count=0;var K=w({name:"Thenable",dependencies:[q],init:function(c){return c}});m.Thenable=q;m.ThenableWorkerModule=K;m.defineWorkerModule=w;m.stringifyFunction=t;Object.defineProperty(m,"__esModule",{value:!0})}) |
{ | ||
"name": "troika-worker-utils", | ||
"version": "0.26.0", | ||
"version": "0.26.1", | ||
"description": "Utilities for executing code in Web Workers", | ||
@@ -17,3 +17,3 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>", | ||
"module:src": "src/index.js", | ||
"gitHead": "4eeeca1356c3017690152bd2becc915ab88a9c18" | ||
"gitHead": "da9622bb62a9c792e166fb1824c3012a7d9f9524" | ||
} |
import Thenable from './Thenable.js' | ||
import { workerBootstrap } from './workerBootstrap.js' | ||
import { defineMainThreadModule } from './mainThreadFallback.js' | ||
import { supportsWorkers } from './supportsWorkers.js' | ||
@@ -12,20 +13,2 @@ let _workerModuleId = 0 | ||
let supportsWorkers = () => { | ||
let supported = false | ||
try { | ||
// TODO additional checks for things like importScripts within the worker? | ||
// Would need to be an async check. | ||
let worker = new Worker( | ||
URL.createObjectURL( | ||
new Blob([''], {type: 'application/javascript'}) | ||
) | ||
) | ||
worker.terminate() | ||
supported = true | ||
} catch(err) { | ||
console.warn(`Troika createWorkerModule: web workers not allowed in current environment; falling back to main thread execution.`, err) | ||
} | ||
supportsWorkers = () => supported | ||
return supported | ||
} | ||
@@ -32,0 +15,0 @@ /** |
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
83882
18
2166