├── webpack ├── .gitignore ├── src │ ├── fibonacci.js │ ├── worker.js │ ├── index.html │ ├── inline.html │ ├── app.js │ └── inline.js ├── package.json ├── dist │ ├── index.html │ ├── inline.html │ ├── 8326e76ae84e026da11a.worker.js │ ├── app-bundle.js │ ├── inline-bundle.js │ ├── 8326e76ae84e026da11a.worker.js.map │ ├── app-bundle.js.map │ └── inline-bundle.js.map └── webpack.config.js ├── worker.js ├── iframe-code.html ├── README.md ├── worker.html ├── iframe.html ├── iframe-crossorigin.html ├── inline-worker.html └── data-passing.html /webpack/.gitignore: -------------------------------------------------------------------------------- 1 | .npm 2 | node_modules/ 3 | *.swp 4 | 5 | -------------------------------------------------------------------------------- /webpack/src/fibonacci.js: -------------------------------------------------------------------------------- 1 | // https://gist.github.com/jfairbank/8d36e4bde9c16dc0bac7 2 | export default function fibonacci(n) { 3 | if (n < 2) { 4 | return 1; 5 | }else { 6 | return fibonacci(n - 2) + fibonacci(n - 1); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /webpack/src/worker.js: -------------------------------------------------------------------------------- 1 | import fibonacci from "./fibonacci.js"; 2 | 3 | onmessage = (e) => { 4 | const num = e.data; 5 | console.log(`Starting calculation for ${num}`); 6 | const result = fibonacci(num); 7 | console.log(`Finished calculation for ${num}`); 8 | postMessage(result); 9 | }; 10 | -------------------------------------------------------------------------------- /worker.js: -------------------------------------------------------------------------------- 1 | // https://gist.github.com/jfairbank/8d36e4bde9c16dc0bac7 2 | function fibonacci(n) { 3 | if (n < 2) { 4 | return 1; 5 | }else { 6 | return fibonacci(n - 2) + fibonacci(n - 1); 7 | } 8 | } 9 | onmessage = (e) => { 10 | const num = e.data; 11 | console.log(`Starting calculation for ${num}`); 12 | const result = fibonacci(num); 13 | console.log(`Finished calculation for ${num}`); 14 | postMessage(result); 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"parallel-processing-in-js", 3 | "version":"0.0.1", 4 | "scripts": { 5 | "build": "NODE_ENV=production webpack -p --progress --profile --colors", 6 | "watch": "webpack-dev-server --hot --inline --progress --colors --watch-poll" 7 | }, 8 | "dependencies": { 9 | }, 10 | "devDependencies": { 11 | "webpack": "1.13.1", 12 | "webpack-dev-server": "1.14.1", 13 | "worker-loader": "0.7.0", 14 | "html-webpack-plugin": "1.7.0", 15 | "babel-core": "6.10.4", 16 | "babel-preset-es2015": "6.9.0", 17 | "babel-loader": "6.2.4" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /iframe-code.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /webpack/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |This example uses a Web Worker. Workers are inherently parallel, and you can see the 32 | calculations are running on different threads.
33 |Click on the Calculate button, and you can see the UI is not affected by the calculations. It 34 | stays responsive, indicating the processing is running on different threads.
35 | 36 |This example uses an IFrame to offload the calculations. But because IFrames are inherently 39 | non-threadsafe, there are no parallel processing takes place.
40 |Click on the Calculate button, and you can see the UI is practically frozen until the last 41 | calculation is completed.
42 | 43 |This example uses an IFrame that is loaded from a different origin. 39 | While the only allowed communication channel is via postMessage, the calculations 40 | are single-threaded.
41 |Click on the Calculate button, and you can see the UI is practically frozen until the last 42 | calculation is completed.
43 | 44 |This example uses an inline Web Worker. It's the same as the previous, but it does not need 57 | the code to be loaded from a different file.
58 |Click on the Calculate button, and you can see the UI is not affected by the calculations. It 59 | stays responsive, indicating the processing is running on different threads.
60 | 61 |This example demonstrates a few ways you can communicate with a Worker.
87 |Please check the console to see the different results.
88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /webpack/dist/8326e76ae84e026da11a.worker.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///8326e76ae84e026da11a.worker.js","webpack:///webpack/bootstrap 8326e76ae84e026da11a","webpack:///./src/worker.js","webpack:///./src/fibonacci.js"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","_interopRequireDefault","obj","__esModule","default","_fibonacci","_fibonacci2","onmessage","e","num","data","console","log","result","postMessage","fibonacci","n","Object","defineProperty","value"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GAE/B,YAMA,SAASW,GAAuBC,GAAO,MAAOA,IAAOA,EAAIC,WAAaD,GAAQE,UAASF,GEpDxF,GAAAG,GAAAf,EAAA,GFkDKgB,EAAcL,EAAuBI,EEhD1CE,WAAY,SAACC,GACZ,GAAMC,GAAMD,EAAEE,IACdC,SAAQC,IAAR,4BAAwCH,EACxC,IAAMI,IAAS,EAAAP,cAAUG,EACzBE,SAAQC,IAAR,4BAAwCH,GACxCK,YAAYD,KFyDP,SAASnB,EAAQD,GAEtB,YGjEc,SAASsB,GAAUC,GACjC,MAAIA,GAAI,EACA,EAEAD,EAAUC,EAAI,GAAKD,EAAUC,EAAI,GH+DzCC,OAAOC,eAAezB,EAAS,cAC9B0B,OAAO,IAER1B,aGtEuBsB","file":"8326e76ae84e026da11a.worker.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tvar _fibonacci = __webpack_require__(1);\n\t\n\tvar _fibonacci2 = _interopRequireDefault(_fibonacci);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\tonmessage = function onmessage(e) {\n\t\tvar num = e.data;\n\t\tconsole.log(\"Starting calculation for \" + num);\n\t\tvar result = (0, _fibonacci2.default)(num);\n\t\tconsole.log(\"Finished calculation for \" + num);\n\t\tpostMessage(result);\n\t};\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t\tvalue: true\n\t});\n\texports.default = fibonacci;\n\t// https://gist.github.com/jfairbank/8d36e4bde9c16dc0bac7\n\tfunction fibonacci(n) {\n\t\tif (n < 2) {\n\t\t\treturn 1;\n\t\t} else {\n\t\t\treturn fibonacci(n - 2) + fibonacci(n - 1);\n\t\t}\n\t}\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** 8326e76ae84e026da11a.worker.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 8326e76ae84e026da11a\n **/","import fibonacci from \"./fibonacci.js\";\n\nonmessage = (e) => {\n\tconst num = e.data;\n\tconsole.log(`Starting calculation for ${num}`);\n\tconst result = fibonacci(num);\n\tconsole.log(`Finished calculation for ${num}`);\n\tpostMessage(result);\n};\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/worker.js\n **/","// https://gist.github.com/jfairbank/8d36e4bde9c16dc0bac7\nexport default function fibonacci(n) {\n\tif (n < 2) {\n\t\treturn 1;\n\t}else {\n\t\treturn fibonacci(n - 2) + fibonacci(n - 1);\n\t}\n}\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/fibonacci.js\n **/"],"sourceRoot":""} -------------------------------------------------------------------------------- /webpack/dist/app-bundle.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///app-bundle.js","webpack:///webpack/bootstrap 0ce272c3333afc869b6d?9649","webpack:///./src/app.js","webpack:///./src/worker.js"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","workerCode","calculateFibonacci","num","Promise","resolve","reject","worker","onerror","e","terminate","onmessage","data","postMessage","window","calc","_loop","i","document","getElementById","value","then","res","Worker"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GAE/B,YE9CD,IAAMW,GAAaX,EAAQ,GAErBY,EAAqB,SAACC,GAC3B,MAAO,IAAIC,SAAQ,SAACC,EAASC,GAC5B,GAAMC,GAAS,GAAIN,EACnBM,GAAOC,QAAU,SAACC,GACjBF,EAAOG,YACPJ,EAAOG,IAERF,EAAOI,UAAY,SAACF,GACnBF,EAAOG,YACPL,EAAQI,EAAEG,OAEXL,EAAOM,YAAYV,KAGrBW,QAAOC,KAAO,WACb,IAAK,GADcC,GAAA,SACVC,GACR,GAAMR,GAAIS,SAASC,eAAe,SAAWF,EAC7CR,GAAEW,MAAQ,iBACVlB,EAAmB,GAAKe,GAAGI,KAAK,SAACC,GAChCb,EAAEW,MAAQE,KAJHL,EAAI,EAAGA,GAAK,EAAGA,IAAKD,EAApBC,KF8DH,CAED,SAASvB,EAAQD,EAASH,GGjFhCI,EAAAD,QAAA,WACA,UAAA8B,QAAAjC,EAAAU,EAAA","file":"app-bundle.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tvar workerCode = __webpack_require__(2);\n\t\n\tvar calculateFibonacci = function calculateFibonacci(num) {\n\t\treturn new Promise(function (resolve, reject) {\n\t\t\tvar worker = new workerCode();\n\t\t\tworker.onerror = function (e) {\n\t\t\t\tworker.terminate();\n\t\t\t\treject(e);\n\t\t\t};\n\t\t\tworker.onmessage = function (e) {\n\t\t\t\tworker.terminate();\n\t\t\t\tresolve(e.data);\n\t\t\t};\n\t\t\tworker.postMessage(num);\n\t\t});\n\t};\n\twindow.calc = function () {\n\t\tvar _loop = function _loop(i) {\n\t\t\tvar e = document.getElementById(\"result\" + i);\n\t\t\te.value = \"Calculating...\";\n\t\t\tcalculateFibonacci(40 + i).then(function (res) {\n\t\t\t\te.value = res;\n\t\t\t});\n\t\t};\n\t\n\t\tfor (var i = 1; i <= 4; i++) {\n\t\t\t_loop(i);\n\t\t}\n\t};\n\n/***/ },\n/* 1 */,\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tmodule.exports = function() {\n\t\treturn new Worker(__webpack_require__.p + \"8326e76ae84e026da11a.worker.js\");\n\t};\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** app-bundle.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 0ce272c3333afc869b6d\n **/","const workerCode = require(\"worker!./worker.js\");\n\nconst calculateFibonacci = (num) => {\n\treturn new Promise((resolve, reject) => {\n\t\tconst worker = new workerCode();\n\t\tworker.onerror = (e) => {\n\t\t\tworker.terminate();\n\t\t\treject(e);\n\t\t};\n\t\tworker.onmessage = (e) => {\n\t\t\tworker.terminate();\n\t\t\tresolve(e.data);\n\t\t}\n\t\tworker.postMessage(num);\n\t});\n};\nwindow.calc = () => {\n\tfor (let i = 1; i <= 4; i++) {\n\t\tconst e = document.getElementById(\"result\" + i);\n\t\te.value = \"Calculating...\";\n\t\tcalculateFibonacci(40 + i).then((res) => {\n\t\t\te.value = res;\n\t\t});\n\t}\n};\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/app.js\n **/","module.exports = function() {\n\treturn new Worker(__webpack_public_path__ + \"8326e76ae84e026da11a.worker.js\");\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/worker-loader!./src/worker.js\n ** module id = 2\n ** module chunks = 1\n **/"],"sourceRoot":""} -------------------------------------------------------------------------------- /webpack/dist/inline-bundle.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///inline-bundle.js","webpack:///webpack/bootstrap 0ce272c3333afc869b6d","webpack:///./src/inline.js","webpack:///./~/worker-loader/createInlineWorker.js","webpack:///./src/worker.js?f231"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","workerCode","calculateFibonacci","num","Promise","resolve","reject","worker","onerror","e","terminate","onmessage","data","postMessage","window","calc","_loop","i","document","getElementById","value","then","res","URL","webkitURL","content","url","blob","BlobBuilder","WebKitBlobBuilder","MozBlobBuilder","MSBlobBuilder","append","getBlob","Blob","Worker","createObjectURL","encodeURIComponent"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GAE/B,YE9CD,IAAMW,GAAaX,EAAQ,GAErBY,EAAqB,SAACC,GAC3B,MAAO,IAAIC,SAAQ,SAACC,EAASC,GAC5B,GAAMC,GAAS,GAAIN,EACnBM,GAAOC,QAAU,SAACC,GACjBF,EAAOG,YACPJ,EAAOG,IAERF,EAAOI,UAAY,SAACF,GACnBF,EAAOG,YACPL,EAAQI,EAAEG,OAEXL,EAAOM,YAAYV,KAGrBW,QAAOC,KAAO,WACb,IAAK,GADcC,GAAA,SACVC,GACR,GAAMR,GAAIS,SAASC,eAAe,SAAWF,EAC7CR,GAAEW,MAAQ,iBACVlB,EAAmB,GAAKe,GAAGI,KAAK,SAACC,GAChCb,EAAEW,MAAQE,KAJHL,EAAI,EAAGA,GAAK,EAAGA,IAAKD,EAApBC,KF+DJ,SAASvB,EAAQD,GG9EvB,GAAA8B,GAAAT,OAAAS,KAAAT,OAAAU,SACA9B,GAAAD,QAAA,SAAAgC,EAAAC,GACA,IACA,IACA,GAAAC,EACA,KACA,GAAAC,GAAAd,OAAAc,aAAAd,OAAAe,mBAAAf,OAAAgB,gBAAAhB,OAAAiB,aACAJ,GAAA,GAAAC,GACAD,EAAAK,OAAAP,GACAE,IAAAM,UACI,MAAAxB,GACJkB,EAAA,GAAAO,OAAAT,IAEA,UAAAU,QAAAZ,EAAAa,gBAAAT,IACG,MAAAlB,GACH,UAAA0B,QAAA,+BAAAE,mBAAAZ,KAEE,MAAAhB,GACF,UAAA0B,QAAAT,MHuFO,CAED,SAAShC,EAAQD,EAASH,GI7GhCI,EAAAD,QAAA,WACA,MAAAH,GAAA,spBAAwtBA,EAAAU,EAAA","file":"inline-bundle.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tvar workerCode = __webpack_require__(3);\n\t\n\tvar calculateFibonacci = function calculateFibonacci(num) {\n\t\treturn new Promise(function (resolve, reject) {\n\t\t\tvar worker = new workerCode();\n\t\t\tworker.onerror = function (e) {\n\t\t\t\tworker.terminate();\n\t\t\t\treject(e);\n\t\t\t};\n\t\t\tworker.onmessage = function (e) {\n\t\t\t\tworker.terminate();\n\t\t\t\tresolve(e.data);\n\t\t\t};\n\t\t\tworker.postMessage(num);\n\t\t});\n\t};\n\twindow.calc = function () {\n\t\tvar _loop = function _loop(i) {\n\t\t\tvar e = document.getElementById(\"result\" + i);\n\t\t\te.value = \"Calculating...\";\n\t\t\tcalculateFibonacci(40 + i).then(function (res) {\n\t\t\t\te.value = res;\n\t\t\t});\n\t\t};\n\t\n\t\tfor (var i = 1; i <= 4; i++) {\n\t\t\t_loop(i);\n\t\t}\n\t};\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string\r\n\t\r\n\tvar URL = window.URL || window.webkitURL;\r\n\tmodule.exports = function(content, url) {\r\n\t\ttry {\r\n\t\t\ttry {\r\n\t\t\t\tvar blob;\r\n\t\t\t\ttry { // BlobBuilder = Deprecated, but widely implemented\r\n\t\t\t\t\tvar BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;\r\n\t\t\t\t\tblob = new BlobBuilder();\r\n\t\t\t\t\tblob.append(content);\r\n\t\t\t\t\tblob = blob.getBlob();\r\n\t\t\t\t} catch(e) { // The proposed API\r\n\t\t\t\t\tblob = new Blob([content]);\r\n\t\t\t\t}\r\n\t\t\t\treturn new Worker(URL.createObjectURL(blob));\r\n\t\t\t} catch(e) {\r\n\t\t\t\treturn new Worker('data:application/javascript,' + encodeURIComponent(content));\r\n\t\t\t}\r\n\t\t} catch(e) {\r\n\t\t\treturn new Worker(url);\r\n\t\t}\r\n\t}\n\n/***/ },\n/* 2 */,\n/* 3 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tmodule.exports = function() {\n\t\treturn __webpack_require__(1)(\"!function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p=\\\"\\\",t(0)}([function(e,t,o){\\\"use strict\\\";function n(e){return e&&e.__esModule?e:{\\\"default\\\":e}}var r=o(1),u=n(r);onmessage=function(e){var t=e.data;console.log(\\\"Starting calculation for \\\"+t);var o=(0,u[\\\"default\\\"])(t);console.log(\\\"Finished calculation for \\\"+t),postMessage(o)}},function(e,t){\\\"use strict\\\";function o(e){return e<2?1:o(e-2)+o(e-1)}Object.defineProperty(t,\\\"__esModule\\\",{value:!0}),t[\\\"default\\\"]=o}]);\\n//# sourceMappingURL=8326e76ae84e026da11a.worker.js.map\", __webpack_require__.p + \"8326e76ae84e026da11a.worker.js\");\n\t};\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** inline-bundle.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 0ce272c3333afc869b6d\n **/","const workerCode = require(\"worker?inline!./worker.js\");\n\nconst calculateFibonacci = (num) => {\n\treturn new Promise((resolve, reject) => {\n\t\tconst worker = new workerCode();\n\t\tworker.onerror = (e) => {\n\t\t\tworker.terminate();\n\t\t\treject(e);\n\t\t};\n\t\tworker.onmessage = (e) => {\n\t\t\tworker.terminate();\n\t\t\tresolve(e.data);\n\t\t}\n\t\tworker.postMessage(num);\n\t});\n};\nwindow.calc = () => {\n\tfor (let i = 1; i <= 4; i++) {\n\t\tconst e = document.getElementById(\"result\" + i);\n\t\te.value = \"Calculating...\";\n\t\tcalculateFibonacci(40 + i).then((res) => {\n\t\t\te.value = res;\n\t\t});\n\t}\n};\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/inline.js\n **/","// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string\r\n\r\nvar URL = window.URL || window.webkitURL;\r\nmodule.exports = function(content, url) {\r\n\ttry {\r\n\t\ttry {\r\n\t\t\tvar blob;\r\n\t\t\ttry { // BlobBuilder = Deprecated, but widely implemented\r\n\t\t\t\tvar BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;\r\n\t\t\t\tblob = new BlobBuilder();\r\n\t\t\t\tblob.append(content);\r\n\t\t\t\tblob = blob.getBlob();\r\n\t\t\t} catch(e) { // The proposed API\r\n\t\t\t\tblob = new Blob([content]);\r\n\t\t\t}\r\n\t\t\treturn new Worker(URL.createObjectURL(blob));\r\n\t\t} catch(e) {\r\n\t\t\treturn new Worker('data:application/javascript,' + encodeURIComponent(content));\r\n\t\t}\r\n\t} catch(e) {\r\n\t\treturn new Worker(url);\r\n\t}\r\n}\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/worker-loader/createInlineWorker.js\n ** module id = 1\n ** module chunks = 0\n **/","module.exports = function() {\n\treturn require(\"!!/home/sashee/Desktop/webworkers/webpack/node_modules/worker-loader/createInlineWorker.js\")(\"!function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p=\\\"\\\",t(0)}([function(e,t,o){\\\"use strict\\\";function n(e){return e&&e.__esModule?e:{\\\"default\\\":e}}var r=o(1),u=n(r);onmessage=function(e){var t=e.data;console.log(\\\"Starting calculation for \\\"+t);var o=(0,u[\\\"default\\\"])(t);console.log(\\\"Finished calculation for \\\"+t),postMessage(o)}},function(e,t){\\\"use strict\\\";function o(e){return e<2?1:o(e-2)+o(e-1)}Object.defineProperty(t,\\\"__esModule\\\",{value:!0}),t[\\\"default\\\"]=o}]);\\n//# sourceMappingURL=8326e76ae84e026da11a.worker.js.map\", __webpack_public_path__ + \"8326e76ae84e026da11a.worker.js\");\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/worker-loader?inline!./src/worker.js\n ** module id = 3\n ** module chunks = 0\n **/"],"sourceRoot":""} --------------------------------------------------------------------------------