/*!
 * processor - 0.1.0 https://github.com/jccazeaux/processor
 *  Copyright (c) 2015 Jean-Christophe Cazeaux.
 *  Licensed under the MIT license.
 * 
 */
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.Processor=r():e.Processor=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r){function t(){i--,a&&a.length>0&&a.shift()()}function n(e){var r=o(e.toString()),t=s.createObjectURL(new Blob([r],{type:"text/javascript"}));return t}function o(e){return"var __fn__ = "+e+";self.addEventListener('message', function(e) {	var args = JSON.parse(e.data);	var result = __fn__.apply(null, args);	var serializedResult;	try {		serializedResult = JSON.stringify(result);	} catch(e) {		throw new Error('Result of thread must be serializable : ' + e.message);	}	self.postMessage(serializedResult);	self.close();});"}var s=window.URL||window.webkitURL,i=0,a=[],u=2,c={promiseAdapter:function(e){return internalPromiseAdapter=e,this},nbThreads:function(e){if(!e||isNaN(e))throw"Illegal argument : must be a number > 0";u=e}},f=function(){var e;if(window.Promise)e=function(e,r){return new window.Promise(e,r)};else{if(!window.Q)throw"No recognized promise library nor ES6 Promise. Try to customize with processor.promiseAdapter";e=function(e,r){return Q.Promise(e,r)}}return e},l=function(e){if("function"!=typeof e)throw"You must pass a function as Processor constructor's argument";var r=n(e);return{exec:function(){var e=arguments,n=f();return new n(function(n,o){var s=function(){var s=new Worker(r);s.addEventListener("message",function(e){n(JSON.parse(e.data)),t()}),s.addEventListener("error",function(e){e.preventDefault(),o(e.message),t()}),i++;var a;try{a=JSON.stringify([].slice.call(e))}catch(u){o("erreur "+u)}s.postMessage(a)};u>i?s():a.push(function(){s()})})}}},d=function(){return{nbThreads:u,activeThreads:i,nbWaitingTasks:a.length}};e.exports={thread:l,config:c,status:d}}])});