-
Notifications
You must be signed in to change notification settings - Fork 1
/
amd_ww-2.0.0.min.js
12 lines (11 loc) · 2.75 KB
/
amd_ww-2.0.0.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/* @license Licensed under MIT license
* See https://raw.githubusercontent.com/adussaq/amd_ww/gh-pages/LICENSE
* @version 2.0.0
* @Compressed with: https://closure-compiler.appspot.com/home
*/
var amd_ww=function(){var n,h,l,u;h=function(c){return console.error("Worker error: "+c+"\nTo display more information for any function type <func_name> instead of <func_name>()")};n=function(c){return function(){var e;try{e=c.apply(null,arguments)}catch(b){h(b)}return e}};l=function(c){var e,b,k,d;c=c||void 0;if(!c)throw"Must define start_obj with at least the workers file.";e=void 0!==c.callback?c.callback:function(){};h=b=c.onError||h;d=void 0!==c.num_workers?c.num_workers:4;d*=1;k=c.filename;
if(!window.Worker)throw"Workers are not available in this browser.";if(isNaN(d)||d!==parseInt(d,10))throw"num_workers must be an integer";if("function"!==typeof e)throw"callback must be a function";if("function"!==typeof b)throw"onError must be a function";if("string"!==typeof k||!k.match(/\.js$/))throw"Must pass in a filename as a string for worker functionality";return u(c)};u=function(c){var e,b,k,d,h,p,f,q,l,m,r,t;e=[];m=[];b=Object.create(Promise);f=[];k=!1;b.clear=function(){var a;delete b.submit;
delete b.all;delete b.clear;delete b.pause;delete b.resume;delete b.race;delete b.resolve;delete b.reject;return d().then(function(g){for(a=0;a<f.length;a+=1)void 0!==f[a]&&(f[a][0].terminate(),f[a]=void 0);delete b.submit;return g})};b.submit=function(a){return n(p)(a)};b.pause=function(){var a=[];b.submit=function(g){g=t(a,g);m.push(g);return g};return r=b.all().then(function(g){k=!0;e=e.concat(a);b.submit=p;return g})};b.resume=function(){r.then(function(a){k=!1;q();return a});return r};b.all=
function(a){return n(d)(a)};b.race=function(a){return a&&0<a.length?Promise.all(a):Promise.all(m)};d=function(a){return a&&0<a.length?Promise.all(a):Promise.all(m)};h=function(a){var g,b,c,d,v;v=f[a][0];f[a][1]=!0;k?f[a][1]=!1:0<e.length?(c=e.shift(),d=c[0],g=c[1],b=c[2],v(d).then(function(a){g(a)},function(a){b(a)}).then(function(){h(a)})):f[a][1]=!1};p=function(a){a=t(e,a);m.push(a["catch"](function(a){console.error(a)}));return a};q=function(){var a;for(a=0;a<f.length;a+=1)if(!f[a][1]){h(a);break}};
t=function(a,b){return new Promise(function(c,d){a.push([b,c,d]);q()})};l=function(a){var b;b=new Worker(a);a=function(a){return new Promise(function(c,d){b.onmessage=function(a){c(a.data)};b.onerror=function(a){d("ERROR: Line "+a.lineno+" in "+a.filename+": "+a.message)};"object"===typeof a?b.postMessage(JSON.parse(JSON.stringify(a))):b.postMessage(a)})};a.terminate=function(){b.terminate()};return a};(function(){var a,b,d;b=void 0!==c.num_workers?c.num_workers:4;b*=1;a=c.filename;for(d=0;d<b;d+=
1)f[d]=[l(a),!1]})();return b};return{startWorkers:function(c){return n(l)(c)}}}();