├── dist ├── ngx-webworker │ ├── public-api.d.ts │ ├── nitinkrmr-ngx-webworker.d.ts │ ├── lib │ │ └── webworker.service.d.ts │ ├── esm5 │ │ ├── public-api.js │ │ ├── nitinkrmr-ngx-webworker.js │ │ └── lib │ │ │ └── webworker.service.js │ ├── esm2015 │ │ ├── public-api.js │ │ ├── nitinkrmr-ngx-webworker.js │ │ └── lib │ │ │ └── webworker.service.js │ ├── nitinkrmr-ngx-webworker.metadata.json │ ├── package.json │ ├── bundles │ │ ├── nitinkrmr-ngx-webworker.umd.min.js │ │ ├── nitinkrmr-ngx-webworker.umd.min.js.map │ │ ├── nitinkrmr-ngx-webworker.umd.js.map │ │ └── nitinkrmr-ngx-webworker.umd.js │ ├── README.md │ ├── fesm2015 │ │ ├── nitinkrmr-ngx-webworker.js.map │ │ └── nitinkrmr-ngx-webworker.js │ └── fesm5 │ │ ├── nitinkrmr-ngx-webworker.js.map │ │ └── nitinkrmr-ngx-webworker.js └── web-wroker-tester │ ├── assets │ └── echo.js │ ├── favicon.ico │ ├── index.html │ ├── runtime-es5.js.map │ ├── runtime-es2015.js.map │ ├── runtime-es5.js │ ├── runtime-es2015.js │ ├── styles-es5.js.map │ ├── styles-es2015.js.map │ ├── styles-es5.js │ └── styles-es2015.js ├── projects ├── ngx-webworker │ ├── src │ │ ├── public-api.ts │ │ ├── lib │ │ │ ├── web-worker.interface.ts │ │ │ └── webworker.service.ts │ │ └── test.ts │ ├── ng-package.json │ ├── tslint.json │ ├── tsconfig.spec.json │ ├── package.json │ ├── tsconfig.lib.json │ ├── karma.conf.js │ └── README.md └── web-wroker-tester │ ├── src │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── assets │ │ └── echo.js │ ├── favicon.ico │ ├── app │ │ ├── result.ts │ │ ├── echo.ts │ │ ├── app.module.ts │ │ ├── app.component.spec.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ └── app.component.ts │ ├── styles.css │ ├── main.ts │ ├── index.html │ ├── test.ts │ └── polyfills.ts │ ├── tsconfig.app.json │ ├── e2e │ ├── tsconfig.json │ ├── src │ │ ├── app.po.ts │ │ └── app.e2e-spec.ts │ └── protractor.conf.js │ ├── tslint.json │ ├── tsconfig.spec.json │ ├── browserslist │ └── karma.conf.js ├── .editorconfig ├── .gitignore ├── tsconfig.json ├── package.json ├── tslint.json ├── README.md └── angular.json /dist/ngx-webworker/public-api.d.ts: -------------------------------------------------------------------------------- 1 | export * from './lib/webworker.service'; 2 | -------------------------------------------------------------------------------- /projects/ngx-webworker/src/public-api.ts: -------------------------------------------------------------------------------- 1 | export * from './lib/webworker.service'; 2 | -------------------------------------------------------------------------------- /dist/web-wroker-tester/assets/echo.js: -------------------------------------------------------------------------------- 1 | onmessage = (e) => { 2 | const me = this; 3 | me.postMessage(e.data); 4 | }; 5 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/assets/echo.js: -------------------------------------------------------------------------------- 1 | onmessage = (e) => { 2 | const me = this; 3 | me.postMessage(e.data); 4 | }; 5 | -------------------------------------------------------------------------------- /dist/web-wroker-tester/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start-javascript/ngx-web-worker/HEAD/dist/web-wroker-tester/favicon.ico -------------------------------------------------------------------------------- /dist/ngx-webworker/nitinkrmr-ngx-webworker.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Generated bundle index. Do not edit. 3 | */ 4 | export * from './public-api'; 5 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start-javascript/ngx-web-worker/HEAD/projects/web-wroker-tester/src/favicon.ico -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/result.ts: -------------------------------------------------------------------------------- 1 | export class Result { 2 | constructor( 3 | public number: number, 4 | public result: number, 5 | public loading: boolean 6 | ) {} 7 | } 8 | -------------------------------------------------------------------------------- /projects/ngx-webworker/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/ngx-webworker", 4 | "lib": { 5 | "entryFile": "src/public-api.ts" 6 | } 7 | } -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | html, 3 | body { 4 | margin: 0; 5 | padding: 0; 6 | font-family: 'PT Sans', sans-serif; 7 | } 8 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/echo.ts: -------------------------------------------------------------------------------- 1 | interface DedicatedWorkerGlobalScope extends Window { 2 | postMessage(data: string): void; 3 | } 4 | 5 | onmessage = function(e) { 6 | const me = this as DedicatedWorkerGlobalScope; 7 | me.postMessage(e.data); 8 | }; 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /projects/ngx-webworker/src/lib/web-worker.interface.ts: -------------------------------------------------------------------------------- 1 | export interface IWebWorkerService { 2 | run(workerFunction: (input: any) => T, data?: any): Promise; 3 | runUrl(url: string, data?: any): Promise; 4 | terminate(promise: Promise): Promise; 5 | getWorker(promise: Promise): Worker; 6 | } 7 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "src/test.ts", 12 | "src/**/*.spec.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/ngx-webworker/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "lib", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "lib", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/ngx-webworker/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/ngx-webworker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nitinkrmr/ngx-webworker", 3 | "version": "8.0.2", 4 | "author": "Nitin Kumar Mishra", 5 | "license": "Mit", 6 | "keywords": [ 7 | "angular", 8 | "web", 9 | "worker" 10 | ], 11 | "peerDependencies": { 12 | "@angular/common": "^8.0.3", 13 | "@angular/core": "^8.0.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { FormsModule } from '@angular/forms'; 3 | import { BrowserModule } from '@angular/platform-browser'; 4 | 5 | import { AppComponent } from './app.component'; 6 | 7 | @NgModule({ 8 | declarations: [AppComponent], 9 | imports: [BrowserModule, FormsModule], 10 | bootstrap: [AppComponent], 11 | providers: [], 12 | }) 13 | export class AppModule {} 14 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebWrokerTester 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /dist/ngx-webworker/lib/webworker.service.d.ts: -------------------------------------------------------------------------------- 1 | export declare class WebworkerService { 2 | private workerFunctionToUrlMap; 3 | private promiseToWorkerMap; 4 | run(workerFunction: (input: any) => T, data?: any): Promise; 5 | runUrl(url: string, data?: any): Promise; 6 | terminate(promise: Promise): Promise; 7 | getWorker(promise: Promise): Worker; 8 | private createPromiseForWorker; 9 | private getOrCreateWorkerUrl; 10 | private createWorkerUrl; 11 | private createPromiseCleaner; 12 | private removePromise; 13 | } 14 | -------------------------------------------------------------------------------- /dist/ngx-webworker/esm5/public-api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | export { WebworkerService } from './lib/webworker.service'; 6 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BuaXRpbmtybXIvbmd4LXdlYndvcmtlci8iLCJzb3VyY2VzIjpbInB1YmxpYy1hcGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLGlDQUFjLHlCQUF5QixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSAnLi9saWIvd2Vid29ya2VyLnNlcnZpY2UnO1xuIl19 -------------------------------------------------------------------------------- /dist/ngx-webworker/esm2015/public-api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | export { WebworkerService } from './lib/webworker.service'; 6 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BuaXRpbmtybXIvbmd4LXdlYndvcmtlci8iLCJzb3VyY2VzIjpbInB1YmxpYy1hcGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLGlDQUFjLHlCQUF5QixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSAnLi9saWIvd2Vid29ya2VyLnNlcnZpY2UnO1xuIl19 -------------------------------------------------------------------------------- /projects/ngx-webworker/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": [], 9 | "lib": [ 10 | "dom", 11 | "es2018" 12 | ] 13 | }, 14 | "angularCompilerOptions": { 15 | "annotateForClosureCompiler": true, 16 | "skipTemplateCodegen": true, 17 | "strictMetadataEmit": true, 18 | "fullTemplateTypeCheck": true, 19 | "strictInjectionParameters": true, 20 | "enableResourceInlining": true 21 | }, 22 | "exclude": [ 23 | "src/test.ts", 24 | "**/*.spec.ts" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /dist/ngx-webworker/nitinkrmr-ngx-webworker.metadata.json: -------------------------------------------------------------------------------- 1 | {"__symbolic":"module","version":4,"metadata":{"WebworkerService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":4,"character":1}}],"members":{"run":[{"__symbolic":"method"}],"runUrl":[{"__symbolic":"method"}],"terminate":[{"__symbolic":"method"}],"getWorker":[{"__symbolic":"method"}],"createPromiseForWorker":[{"__symbolic":"method"}],"getOrCreateWorkerUrl":[{"__symbolic":"method"}],"createWorkerUrl":[{"__symbolic":"method"}],"createPromiseCleaner":[{"__symbolic":"method"}],"removePromise":[{"__symbolic":"method"}]}}},"origins":{"WebworkerService":"./lib/webworker.service"},"importAs":"@nitinkrmr/ngx-webworker"} -------------------------------------------------------------------------------- /dist/ngx-webworker/esm2015/nitinkrmr-ngx-webworker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | /** 6 | * Generated bundle index. Do not edit. 7 | */ 8 | export { WebworkerService } from './public-api'; 9 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibml0aW5rcm1yLW5neC13ZWJ3b3JrZXIuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9Abml0aW5rcm1yL25neC13ZWJ3b3JrZXIvIiwic291cmNlcyI6WyJuaXRpbmtybXItbmd4LXdlYndvcmtlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBSUEsaUNBQWMsY0FBYyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZWQgYnVuZGxlIGluZGV4LiBEbyBub3QgZWRpdC5cbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL3B1YmxpYy1hcGknO1xuIl19 -------------------------------------------------------------------------------- /dist/ngx-webworker/esm5/nitinkrmr-ngx-webworker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | /** 6 | * Generated bundle index. Do not edit. 7 | */ 8 | export { WebworkerService } from './public-api'; 9 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibml0aW5rcm1yLW5neC13ZWJ3b3JrZXIuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9Abml0aW5rcm1yL25neC13ZWJ3b3JrZXIvIiwic291cmNlcyI6WyJuaXRpbmtybXItbmd4LXdlYndvcmtlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBSUEsaUNBQWMsY0FBYyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZWQgYnVuZGxlIGluZGV4LiBEbyBub3QgZWRpdC5cbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL3B1YmxpYy1hcGknO1xuIl19 -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /projects/ngx-webworker/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone'; 4 | import 'zone.js/dist/zone-testing'; 5 | import { getTestBed } from '@angular/core/testing'; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | declare const require: any; 12 | 13 | // First, initialize the Angular testing environment. 14 | getTestBed().initTestEnvironment( 15 | BrowserDynamicTestingModule, 16 | platformBrowserDynamicTesting() 17 | ); 18 | // Then we find all the tests. 19 | const context = require.context('./', true, /\.spec\.ts$/); 20 | // And load the modules. 21 | context.keys().map(context); 22 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to web-wroker-tester!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /tmp 5 | /out-tsc 6 | # Only exists if Bazel was run 7 | /bazel-out 8 | 9 | # dependencies 10 | /node_modules 11 | 12 | # profiling files 13 | chrome-profiler-events.json 14 | speed-measure-plugin.json 15 | 16 | # IDEs and editors 17 | /.idea 18 | .project 19 | .classpath 20 | .c9/ 21 | *.launch 22 | .settings/ 23 | *.sublime-workspace 24 | 25 | # IDE - VSCode 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | .history/* 32 | 33 | # misc 34 | /.sass-cache 35 | /connect.lock 36 | /coverage 37 | /libpeerconnection.log 38 | npm-debug.log 39 | yarn-error.log 40 | testem.log 41 | /typings 42 | 43 | # System Files 44 | .DS_Store 45 | Thumbs.db 46 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ], 21 | "paths": { 22 | "web-worker": [ 23 | "dist/web-worker" 24 | ], 25 | "web-worker/*": [ 26 | "dist/web-worker/*" 27 | ], 28 | "ngx-webworker": [ 29 | "dist/ngx-webworker" 30 | ], 31 | "ngx-webworker/*": [ 32 | "dist/ngx-webworker/*" 33 | ] 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /dist/ngx-webworker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nitinkrmr/ngx-webworker", 3 | "version": "8.0.2", 4 | "author": "Nitin Kumar Mishra", 5 | "license": "Mit", 6 | "keywords": [ 7 | "angular", 8 | "web", 9 | "worker" 10 | ], 11 | "peerDependencies": { 12 | "@angular/common": "^8.0.3", 13 | "@angular/core": "^8.0.3" 14 | }, 15 | "main": "bundles/nitinkrmr-ngx-webworker.umd.js", 16 | "module": "fesm5/nitinkrmr-ngx-webworker.js", 17 | "es2015": "fesm2015/nitinkrmr-ngx-webworker.js", 18 | "esm5": "esm5/nitinkrmr-ngx-webworker.js", 19 | "esm2015": "esm2015/nitinkrmr-ngx-webworker.js", 20 | "fesm5": "fesm5/nitinkrmr-ngx-webworker.js", 21 | "fesm2015": "fesm2015/nitinkrmr-ngx-webworker.js", 22 | "typings": "nitinkrmr-ngx-webworker.d.ts", 23 | "metadata": "nitinkrmr-ngx-webworker.metadata.json", 24 | "sideEffects": false, 25 | "dependencies": { 26 | "tslib": "^1.9.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /dist/web-wroker-tester/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebWrokerTester 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /projects/ngx-webworker/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/ngx-webworker'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'web-wroker-tester'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('web-wroker-tester'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to web-wroker-tester!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/web-wroker-tester'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .spin-me-baby { 2 | animation: spin 4s linear infinite; 3 | } 4 | @keyframes spin { 5 | 100% { 6 | transform: rotate(360deg); 7 | } 8 | } 9 | .zoom-me-baby { 10 | animation: zoom 4s linear infinite; 11 | } 12 | @keyframes zoom { 13 | 50% { 14 | font-size: 2em; 15 | } 16 | 100% { 17 | font-size: 1em; 18 | } 19 | } 20 | :host { 21 | padding: 20px; 22 | display: block; 23 | } 24 | :host input:focus, 25 | :host button:focus { 26 | outline: none; 27 | border: 1px solid #3e8ef7; 28 | } 29 | 30 | .mt-0 { 31 | margin-top: 0; 32 | } 33 | .mt-10 { 34 | margin-top: 10px; 35 | } 36 | 37 | .mt-20 { 38 | margin-top: 20px; 39 | } 40 | 41 | input { 42 | padding: 10px 20px; 43 | border-radius: 4px; 44 | border: none; 45 | background: #eeeeee; 46 | margin: 0 20px; 47 | font-size: 14px; 48 | border: 1px solid transparent; 49 | } 50 | 51 | button { 52 | padding: 8px 20px; 53 | font-size: 14px; 54 | margin-right: 20px; 55 | background: #3e8ef7; 56 | border: 1px solid #3e8ef7; 57 | border-radius: 4px; 58 | cursor: pointer; 59 | color: #ffffff; 60 | } 61 | button:hover, 62 | button:focus { 63 | background: #0966df; 64 | } 65 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

calculating fibonacci using web worker

2 |
3 |
4 | calculate fib(n) from 5 | 6 | to: 7 | 8 |
9 | 10 | 13 |
14 |
15 |

16 | fib({{ result.number }}) = 17 | ... calculating ... 18 | {{ result.result }} 19 |

20 |
21 | 22 |

calculating fibonacci using main UI thread

23 |
24 |
25 | calculate fib(n) from 26 | 31 | to: 32 | 33 |
34 | 37 |
38 |
39 |
40 | 41 | took {{ synchronousDuration }} seconds 42 | 43 |
44 |

45 | fib({{ result.number }}) = {{ result.result }} 46 |

47 |
48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngx-webworker", 3 | "version": "8.0.1", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build:app": "ng build web-wroker-tester --base-href ngx-web-worker", 8 | "build:lib": "ng build ngx-webworker", 9 | "publish:git": "git subtree push --prefix dist/web-wroker-tester origin gh-pages", 10 | "publish:npm": "cd dist/ngx-webworker && npm publish --access=public", 11 | "test": "ng test", 12 | "lint": "ng lint", 13 | "e2e": "ng e2e" 14 | }, 15 | "dependencies": { 16 | "@angular/animations": "~8.0.3", 17 | "@angular/common": "~8.0.3", 18 | "@angular/compiler": "~8.0.3", 19 | "@angular/core": "~8.0.3", 20 | "@angular/forms": "~8.0.3", 21 | "@angular/platform-browser": "~8.0.3", 22 | "@angular/platform-browser-dynamic": "~8.0.3", 23 | "@angular/router": "~8.0.3", 24 | "rxjs": "~6.4.0", 25 | "tslib": "^1.9.0", 26 | "zone.js": "~0.9.1" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~0.800.6", 30 | "@angular-devkit/build-ng-packagr": "~0.800.6", 31 | "@angular/cli": "~8.0.6", 32 | "@angular/compiler-cli": "~8.0.3", 33 | "@angular/language-service": "~8.0.3", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~3.3.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "^5.0.0", 38 | "jasmine-core": "~3.4.0", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~4.1.0", 41 | "karma-chrome-launcher": "~2.2.0", 42 | "karma-coverage-istanbul-reporter": "~2.0.1", 43 | "karma-jasmine": "~2.0.1", 44 | "karma-jasmine-html-reporter": "^1.4.0", 45 | "ng-packagr": "^5.1.0", 46 | "protractor": "~5.4.0", 47 | "ts-node": "~7.0.0", 48 | "tsickle": "^0.35.0", 49 | "tslint": "~5.15.0", 50 | "typescript": "~3.4.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dist/ngx-webworker/bundles/nitinkrmr-ngx-webworker.umd.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("@nitinkrmr/ngx-webworker",["exports","@angular/core"],r):r(((e=e||self).nitinkrmr=e.nitinkrmr||{},e.nitinkrmr["ngx-webworker"]={}),e.ng.core)}(this,function(e,r){"use strict";var t=function(){function e(){this.workerFunctionToUrlMap=new WeakMap,this.promiseToWorkerMap=new WeakMap}return e.prototype.run=function(e,r){var t=this.getOrCreateWorkerUrl(e);return this.runUrl(t,r)},e.prototype.runUrl=function(e,r){var t=new Worker(e),o=this.createPromiseForWorker(t,r),n=this.createPromiseCleaner(o);return this.promiseToWorkerMap.set(o,t),o.then(n)["catch"](n),o},e.prototype.terminate=function(e){return this.removePromise(e)},e.prototype.getWorker=function(e){return this.promiseToWorkerMap.get(e)},e.prototype.createPromiseForWorker=function(e,r){return new Promise(function(t,o){e.addEventListener("message",function(e){return t(e.data)}),e.addEventListener("error",o),e.postMessage(r)})},e.prototype.getOrCreateWorkerUrl=function(e){if(!this.workerFunctionToUrlMap.has(e)){var r=this.createWorkerUrl(e);return this.workerFunctionToUrlMap.set(e,r),r}return this.workerFunctionToUrlMap.get(e)},e.prototype.createWorkerUrl=function(e){var r=e.toString(),t=new Blob(["\n self.addEventListener('message', function(e) {\n postMessage(("+r+")(e.data));\n });\n "],{type:"text/javascript"});return URL.createObjectURL(t)},e.prototype.createPromiseCleaner=function(e){var r=this;return function(t){return r.removePromise(e),t}},e.prototype.removePromise=function(e){var r=this.promiseToWorkerMap.get(e);return r&&r.terminate(),this.promiseToWorkerMap["delete"](e),e},e.decorators=[{type:r.Injectable}],e}();e.WebworkerService=t,Object.defineProperty(e,"__esModule",{value:!0})}); 2 | //# sourceMappingURL=nitinkrmr-ngx-webworker.umd.min.js.map -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": ["codelyzer"], 4 | "rules": { 5 | "array-type": false, 6 | "arrow-parens": false, 7 | "deprecation": { 8 | "severity": "warning" 9 | }, 10 | "import-blacklist": [true, "rxjs/Rx"], 11 | "interface-name": false, 12 | "max-classes-per-file": false, 13 | "max-line-length": [true, 140], 14 | "member-access": false, 15 | "member-ordering": [ 16 | true, 17 | { 18 | "order": [ 19 | "static-field", 20 | "instance-field", 21 | "static-method", 22 | "instance-method" 23 | ] 24 | } 25 | ], 26 | "naming-convention": [ 27 | true, 28 | { 29 | "type": "member", 30 | "modifiers": "private", 31 | "leadingUnderscore": "require" 32 | } 33 | ], 34 | "no-consecutive-blank-lines": false, 35 | "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], 36 | "no-empty": false, 37 | "no-inferrable-types": [true, "ignore-params"], 38 | "no-non-null-assertion": true, 39 | "no-redundant-jsdoc": true, 40 | "no-switch-case-fall-through": true, 41 | "no-use-before-declare": true, 42 | "no-var-requires": false, 43 | "object-literal-key-quotes": [true, "as-needed"], 44 | "object-literal-sort-keys": false, 45 | "ordered-imports": false, 46 | "quotemark": [true, "single"], 47 | "trailing-comma": false, 48 | "component-class-suffix": true, 49 | "contextual-lifecycle": true, 50 | "directive-class-suffix": true, 51 | "no-conflicting-lifecycle": true, 52 | "no-host-metadata-property": true, 53 | "no-input-rename": true, 54 | "no-inputs-metadata-property": true, 55 | "no-output-native": true, 56 | "no-output-on-prefix": true, 57 | "no-output-rename": true, 58 | "no-outputs-metadata-property": true, 59 | "template-banana-in-box": true, 60 | "template-no-negated-async": true, 61 | "use-lifecycle-interface": true, 62 | "use-pipe-transform-interface": true 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /projects/ngx-webworker/src/lib/webworker.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | type CallbackFunction = () => void; 4 | 5 | @Injectable() 6 | export class WebworkerService { 7 | private workerFunctionToUrlMap = new WeakMap(); 8 | private promiseToWorkerMap = new WeakMap, Worker>(); 9 | 10 | run(workerFunction: (input: any) => T, data?: any): Promise { 11 | const url = this.getOrCreateWorkerUrl(workerFunction); 12 | return this.runUrl(url, data); 13 | } 14 | 15 | runUrl(url: string, data?: any): Promise { 16 | const worker = new Worker(url); 17 | const promise = this.createPromiseForWorker(worker, data); 18 | const promiseCleaner = this.createPromiseCleaner(promise); 19 | 20 | this.promiseToWorkerMap.set(promise, worker); 21 | 22 | promise.then(promiseCleaner).catch(promiseCleaner); 23 | 24 | return promise; 25 | } 26 | 27 | terminate(promise: Promise): Promise { 28 | return this.removePromise(promise); 29 | } 30 | 31 | getWorker(promise: Promise): Worker { 32 | return this.promiseToWorkerMap.get(promise); 33 | } 34 | 35 | private createPromiseForWorker(worker: Worker, data: any) { 36 | return new Promise((resolve, reject) => { 37 | worker.addEventListener('message', (event) => resolve(event.data)); 38 | worker.addEventListener('error', reject); 39 | worker.postMessage(data); 40 | }); 41 | } 42 | 43 | private getOrCreateWorkerUrl(fn: any): string { 44 | if (!this.workerFunctionToUrlMap.has(fn)) { 45 | const url = this.createWorkerUrl(fn); 46 | this.workerFunctionToUrlMap.set(fn, url); 47 | return url; 48 | } 49 | return this.workerFunctionToUrlMap.get(fn); 50 | } 51 | 52 | private createWorkerUrl(resolve: CallbackFunction): string { 53 | const resolveString = resolve.toString(); 54 | const webWorkerTemplate = ` 55 | self.addEventListener('message', function(e) { 56 | postMessage((${resolveString})(e.data)); 57 | }); 58 | `; 59 | const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 60 | return URL.createObjectURL(blob); 61 | } 62 | 63 | private createPromiseCleaner(promise: Promise): (input: any) => T { 64 | return (event) => { 65 | this.removePromise(promise); 66 | return event; 67 | }; 68 | } 69 | 70 | private removePromise(promise: Promise): Promise { 71 | const worker = this.promiseToWorkerMap.get(promise); 72 | if (worker) { 73 | worker.terminate(); 74 | } 75 | this.promiseToWorkerMap.delete(promise); 76 | return promise; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is this? 2 | 3 | [Web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) 4 | service for [Angular](https://angular.io). 5 | 6 | ## [Demo](https://start-javascript.github.io/ngx-web-worker/) 7 | 8 | # Install 9 | 10 | ```shell 11 | npm i ngx-web-worker 12 | ``` 13 | 14 | # API 15 | 16 | ```javascript 17 | export interface IWebWorkerService { 18 | run(workerFunction: (any) => T, data?: any): Promise; 19 | runUrl(url: string, data?: any): Promise; 20 | terminate(promise: Promise): Promise; 21 | } 22 | ``` 23 | 24 | - `run` 25 | 26 | - `workerFunction`: 27 | 28 | - Must be a self-contained function. Cannot reference outside variables. 29 | - You can import other libraries with 30 | [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts) 31 | though 32 | - These are okay: 33 | - ```javascript 34 | run(input => input * input, 10); 35 | 36 | run(input => { 37 | const square = num => num * num; 38 | return square(input); 39 | }, 10); 40 | 41 | const someFunction = (input) => input * input); 42 | run(someFunction, 10); 43 | 44 | class Runner { 45 | private webWorkerService = new WebWorkerService(); 46 | constructor() { 47 | this.webWorkerService.run(this.someFunction, 10); 48 | } 49 | someFunction() { 50 | return input * input; 51 | } 52 | } 53 | ``` 54 | 55 | - These will probably **NOT** work: 56 | - ```javascript 57 | // this is not okay because inside the context of the web worker `this` is not the same `this` as here. 58 | run(input => this.square(input), 10); 59 | 60 | // this is not okay because `_` doesn't exist in the web worker context (assuming tht `_` is available here to begin with) 61 | run(input => { 62 | return _.uniqueId() * input; 63 | }, 10); 64 | ``` 65 | 66 | - `data`: 67 | [serializable data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) 68 | 69 | - `runUrl`: Basically the same as 70 | - `url`: The url you would use to create a 71 | [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) instance 72 | - `data`: Same as the `run` method 73 | - `terminate`: Calling this will 74 | [`terminate`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) the web worker, 75 | if it is still running. 76 | - `promise`: The `Promise` instance returned by `run` or `runUrl`. 77 | 78 | # Example 79 | 80 | Check out [ngx-web-worker-example](https://github.com/nitinkrmr/ngx-web-worker-example) for a 81 | sample project, or see [`app/app.component.ts`](app/app.component.ts) for usage with an Angular 82 | application. 83 | 84 | ``` 85 | export class AppComponent implements OnInit { 86 | constructor(private _webWorkerService: WebWorkerService) { 87 | } 88 | 89 | ngOnInit() { 90 | const input = 100; 91 | const promise = this._webWorkerService.run(this.someCPUHeavyFunction, input); 92 | promise.then(result => console.log(result)); 93 | } 94 | 95 | someCPUHeavyFunction (input) { 96 | return input * 10; 97 | } 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /dist/ngx-webworker/README.md: -------------------------------------------------------------------------------- 1 | # What is this? 2 | 3 | [Web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) 4 | service for [Angular](https://angular.io). 5 | 6 | ## [Demo](https://github.com/start-javascript/ngx-web-worker) 7 | 8 | # Install 9 | 10 | ```shell 11 | npm i ngx-web-worker 12 | ``` 13 | 14 | # API 15 | 16 | ```javascript 17 | export interface IWebWorkerService { 18 | run(workerFunction: (any) => T, data?: any): Promise; 19 | runUrl(url: string, data?: any): Promise; 20 | terminate(promise: Promise): Promise; 21 | } 22 | ``` 23 | 24 | - `run` 25 | 26 | - `workerFunction`: 27 | 28 | - Must be a self-contained function. Cannot reference outside variables. 29 | - You can import other libraries with 30 | [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts) 31 | though 32 | - These are okay: 33 | - ```javascript 34 | run(input => input * input, 10); 35 | 36 | run(input => { 37 | const square = num => num * num; 38 | return square(input); 39 | }, 10); 40 | 41 | const someFunction = (input) => input * input); 42 | run(someFunction, 10); 43 | 44 | class Runner { 45 | private webWorkerService = new WebWorkerService(); 46 | constructor() { 47 | this.webWorkerService.run(this.someFunction, 10); 48 | } 49 | someFunction() { 50 | return input * input; 51 | } 52 | } 53 | ``` 54 | 55 | - These will probably **NOT** work: 56 | - ```javascript 57 | // this is not okay because inside the context of the web worker `this` is not the same `this` as here. 58 | run(input => this.square(input), 10); 59 | 60 | // this is not okay because `_` doesn't exist in the web worker context (assuming tht `_` is available here to begin with) 61 | run(input => { 62 | return _.uniqueId() * input; 63 | }, 10); 64 | ``` 65 | 66 | - `data`: 67 | [serializable data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) 68 | 69 | - `runUrl`: Basically the same as 70 | - `url`: The url you would use to create a 71 | [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) instance 72 | - `data`: Same as the `run` method 73 | - `terminate`: Calling this will 74 | [`terminate`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) the web worker, 75 | if it is still running. 76 | - `promise`: The `Promise` instance returned by `run` or `runUrl`. 77 | 78 | # Example 79 | 80 | Check out [ngx-web-worker-example](https://github.com/nitinkrmr/ngx-web-worker-example) for a 81 | sample project, or see [`app/app.component.ts`](app/app.component.ts) for usage with an Angular 82 | application. 83 | 84 | ``` 85 | export class AppComponent implements OnInit { 86 | constructor(private _webWorkerService: WebWorkerService) { 87 | } 88 | 89 | ngOnInit() { 90 | const input = 100; 91 | const promise = this._webWorkerService.run(this.someCPUHeavyFunction, input); 92 | promise.then(result => console.log(result)); 93 | } 94 | 95 | someCPUHeavyFunction (input) { 96 | return input * 10; 97 | } 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /projects/ngx-webworker/README.md: -------------------------------------------------------------------------------- 1 | # What is this? 2 | 3 | [Web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) 4 | service for [Angular](https://angular.io). 5 | 6 | ## [Demo](https://start-javascript.github.io/ngx-web-worker/) 7 | 8 | # Install 9 | 10 | ```shell 11 | npm i ngx-web-worker 12 | ``` 13 | 14 | # API 15 | 16 | ```javascript 17 | export interface IWebWorkerService { 18 | run(workerFunction: (any) => T, data?: any): Promise; 19 | runUrl(url: string, data?: any): Promise; 20 | terminate(promise: Promise): Promise; 21 | } 22 | ``` 23 | 24 | - `run` 25 | 26 | - `workerFunction`: 27 | 28 | - Must be a self-contained function. Cannot reference outside variables. 29 | - You can import other libraries with 30 | [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts) 31 | though 32 | - These are okay: 33 | - ```javascript 34 | run(input => input * input, 10); 35 | 36 | run(input => { 37 | const square = num => num * num; 38 | return square(input); 39 | }, 10); 40 | 41 | const someFunction = (input) => input * input); 42 | run(someFunction, 10); 43 | 44 | class Runner { 45 | private webWorkerService = new WebWorkerService(); 46 | constructor() { 47 | this.webWorkerService.run(this.someFunction, 10); 48 | } 49 | someFunction() { 50 | return input * input; 51 | } 52 | } 53 | ``` 54 | 55 | - These will probably **NOT** work: 56 | - ```javascript 57 | // this is not okay because inside the context of the web worker `this` is not the same `this` as here. 58 | run(input => this.square(input), 10); 59 | 60 | // this is not okay because `_` doesn't exist in the web worker context (assuming tht `_` is available here to begin with) 61 | run(input => { 62 | return _.uniqueId() * input; 63 | }, 10); 64 | ``` 65 | 66 | - `data`: 67 | [serializable data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) 68 | 69 | - `runUrl`: Basically the same as 70 | - `url`: The url you would use to create a 71 | [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) instance 72 | - `data`: Same as the `run` method 73 | - `terminate`: Calling this will 74 | [`terminate`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) the web worker, 75 | if it is still running. 76 | - `promise`: The `Promise` instance returned by `run` or `runUrl`. 77 | 78 | # Example 79 | 80 | Check out [ngx-web-worker-example](https://github.com/nitinkrmr/ngx-web-worker-example) for a 81 | sample project, or see [`app/app.component.ts`](app/app.component.ts) for usage with an Angular 82 | application. 83 | 84 | ``` 85 | export class AppComponent implements OnInit { 86 | constructor(private _webWorkerService: WebWorkerService) { 87 | } 88 | 89 | ngOnInit() { 90 | const input = 100; 91 | const promise = this._webWorkerService.run(this.someCPUHeavyFunction, input); 92 | promise.then(result => console.log(result)); 93 | } 94 | 95 | someCPUHeavyFunction (input) { 96 | return input * 10; 97 | } 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /projects/web-wroker-tester/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { WebworkerService } from 'ngx-webworker'; 2 | 3 | import { Component, OnInit } from '@angular/core'; 4 | 5 | import { Result } from './result'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: './app.component.html', 10 | styleUrls: ['./app.component.css'], 11 | providers: [WebworkerService], 12 | }) 13 | export class AppComponent implements OnInit { 14 | public webWorkerResults: any[] = []; 15 | public webWorkerStart = 35; 16 | public webWorkerEnd = 45; 17 | public synchronousStart = 35; 18 | public synchronousEnd = 38; 19 | public synchronousResults: any[] = []; 20 | public synchronousDuration = 0; 21 | private promises: Promise[] = []; 22 | 23 | constructor(private _webWorkerService: WebworkerService) {} 24 | 25 | ngOnInit() { 26 | const promise = this._webWorkerService.run(() => 'polo', 0); 27 | const worker = this._webWorkerService.getWorker(promise); 28 | worker.addEventListener('message', (event) => { 29 | console.log('Worker Response => ', event.data); 30 | }); 31 | this.startExternalRequest(); 32 | } 33 | 34 | startWebWorkerCalculation() { 35 | let pointer = this.webWorkerStart; 36 | const end = this.webWorkerEnd; 37 | 38 | this.stopWebWorkerCalculation(); 39 | while (pointer <= end) { 40 | this.webWorkerCalculate(pointer); 41 | pointer++; 42 | } 43 | } 44 | 45 | stopWebWorkerCalculation() { 46 | this.promises.forEach((promise) => { 47 | this._webWorkerService.terminate(promise); 48 | }); 49 | this.promises.length = 0; 50 | this.webWorkerResults.length = 0; 51 | } 52 | 53 | startSynchronousCalculation() { 54 | let pointer = this.synchronousStart; 55 | const end = this.synchronousEnd; 56 | 57 | this.synchronousResults.length = 0; 58 | 59 | const start = new Date(); 60 | while (pointer <= end) { 61 | const result = new Result(pointer, this.fib(pointer), false); 62 | this.synchronousResults.push(result); 63 | pointer++; 64 | } 65 | this.synchronousDuration = (new Date().getTime() - start.getTime()) / 1000; 66 | } 67 | 68 | startExternalRequest() { 69 | const promises = []; 70 | promises.push(this._webWorkerService.runUrl('/assets/echo.js', 'marco')); 71 | promises.push(this._webWorkerService.run(() => 'polo', 0)); 72 | 73 | promises.forEach((promise) => { 74 | const worker = this._webWorkerService.getWorker(promise); 75 | worker.addEventListener('message', (event) => { 76 | console.log('getWorker', event.data); 77 | }); 78 | }); 79 | 80 | Promise.all(promises) 81 | .then((response) => console.log(response)) 82 | .catch((error) => console.error(error)); 83 | } 84 | 85 | private webWorkerCalculate(n: number) { 86 | const promise = this._webWorkerService.run(this.fib, n); 87 | const result = new Result(n, 0, true); 88 | this.webWorkerResults.push(result); 89 | this.promises.push(promise); 90 | 91 | promise.then((response) => { 92 | result.result = response; 93 | result.loading = false; 94 | }); 95 | } 96 | 97 | private fib = (n: number) => { 98 | const fib = (n: number): number => { 99 | if (n < 2) { 100 | return 1; 101 | } 102 | return fib(n - 1) + fib(n - 2); 103 | }; 104 | 105 | return fib(n); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /dist/ngx-webworker/bundles/nitinkrmr-ngx-webworker.umd.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["ng://@nitinkrmr/ngx-webworker/lib/webworker.service.ts"],"names":["WebworkerService","this","workerFunctionToUrlMap","WeakMap","promiseToWorkerMap","prototype","run","workerFunction","data","url","getOrCreateWorkerUrl","runUrl","worker","Worker","promise","createPromiseForWorker","promiseCleaner","createPromiseCleaner","set","then","catch","terminate","removePromise","getWorker","get","Promise","resolve","reject","addEventListener","event","postMessage","fn","has","createWorkerUrl","resolveString","toString","blob","Blob","type","URL","createObjectURL","_this","delete","Injectable"],"mappings":"qUAAA,IAAAA,EAAA,WAIA,SAAAA,IAEUC,KAAAC,uBAAyB,IAAIC,QAC7BF,KAAAG,mBAAqB,IAAID,QAsEnC,OApEEH,EAAAK,UAAAC,IAAA,SAAOC,EAAmCC,OAClCC,EAAMR,KAAKS,qBAAqBH,GACtC,OAAON,KAAKU,OAAOF,EAAKD,IAG1BR,EAAAK,UAAAM,OAAA,SAAOF,EAAaD,OACZI,EAAS,IAAIC,OAAOJ,GACpBK,EAAUb,KAAKc,uBAAuBH,EAAQJ,GAC9CQ,EAAiBf,KAAKgB,qBAAqBH,GAMjD,OAJAb,KAAKG,mBAAmBc,IAAIJ,EAASF,GAErCE,EAAQK,KAAKH,GAAgBI,SAAMJ,GAE5BF,GAGTd,EAAAK,UAAAgB,UAAA,SAAaP,GACX,OAAOb,KAAKqB,cAAcR,IAG5Bd,EAAAK,UAAAkB,UAAA,SAAUT,GACR,OAAOb,KAAKG,mBAAmBoB,IAAIV,IAG7Bd,EAAAK,UAAAU,uBAAR,SAAkCH,EAAgBJ,GAChD,OAAO,IAAIiB,QAAO,SAAKC,EAASC,GAC9Bf,EAAOgB,iBAAiB,UAAS,SAAGC,GAAU,OAAAH,EAAQG,EAAMrB,QAC5DI,EAAOgB,iBAAiB,QAASD,GACjCf,EAAOkB,YAAYtB,MAIfR,EAAAK,UAAAK,qBAAR,SAA6BqB,GAC3B,IAAK9B,KAAKC,uBAAuB8B,IAAID,GAAK,KAClCtB,EAAMR,KAAKgC,gBAAgBF,GAEjC,OADA9B,KAAKC,uBAAuBgB,IAAIa,EAAItB,GAC7BA,EAET,OAAOR,KAAKC,uBAAuBsB,IAAIO,IAGjC/B,EAAAK,UAAA4B,gBAAR,SAAwBP,OAChBQ,EAAgBR,EAAQS,WAMxBC,EAAO,IAAIC,KAAK,CALI,gFAEPH,EAAa,gCAGW,CAAEI,KAAM,oBACnD,OAAOC,IAAIC,gBAAgBJ,IAGrBpC,EAAAK,UAAAY,qBAAR,SAAgCH,GAAhC,IAAA2B,EAAAxC,KACE,OAAA,SAAQ4B,GAEN,OADAY,EAAKnB,cAAcR,GACZe,IAIH7B,EAAAK,UAAAiB,cAAR,SAAyBR,OACjBF,EAASX,KAAKG,mBAAmBoB,IAAIV,GAK3C,OAJIF,GACFA,EAAOS,YAETpB,KAAKG,mBAAmBsC,UAAO5B,GACxBA,uBAvEV6B,EAAAA,aAyED3C,EA7EA","sourcesContent":["import { Injectable } from '@angular/core';\n\ntype CallbackFunction = () => void;\n\n@Injectable()\nexport class WebworkerService {\n private workerFunctionToUrlMap = new WeakMap();\n private promiseToWorkerMap = new WeakMap, Worker>();\n\n run(workerFunction: (input: any) => T, data?: any): Promise {\n const url = this.getOrCreateWorkerUrl(workerFunction);\n return this.runUrl(url, data);\n }\n\n runUrl(url: string, data?: any): Promise {\n const worker = new Worker(url);\n const promise = this.createPromiseForWorker(worker, data);\n const promiseCleaner = this.createPromiseCleaner(promise);\n\n this.promiseToWorkerMap.set(promise, worker);\n\n promise.then(promiseCleaner).catch(promiseCleaner);\n\n return promise;\n }\n\n terminate(promise: Promise): Promise {\n return this.removePromise(promise);\n }\n\n getWorker(promise: Promise): Worker {\n return this.promiseToWorkerMap.get(promise);\n }\n\n private createPromiseForWorker(worker: Worker, data: any) {\n return new Promise((resolve, reject) => {\n worker.addEventListener('message', (event) => resolve(event.data));\n worker.addEventListener('error', reject);\n worker.postMessage(data);\n });\n }\n\n private getOrCreateWorkerUrl(fn: any): string {\n if (!this.workerFunctionToUrlMap.has(fn)) {\n const url = this.createWorkerUrl(fn);\n this.workerFunctionToUrlMap.set(fn, url);\n return url;\n }\n return this.workerFunctionToUrlMap.get(fn);\n }\n\n private createWorkerUrl(resolve: CallbackFunction): string {\n const resolveString = resolve.toString();\n const webWorkerTemplate = `\n self.addEventListener('message', function(e) {\n postMessage((${resolveString})(e.data));\n });\n `;\n const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' });\n return URL.createObjectURL(blob);\n }\n\n private createPromiseCleaner(promise: Promise): (input: any) => T {\n return (event) => {\n this.removePromise(promise);\n return event;\n };\n }\n\n private removePromise(promise: Promise): Promise {\n const worker = this.promiseToWorkerMap.get(promise);\n if (worker) {\n worker.terminate();\n }\n this.promiseToWorkerMap.delete(promise);\n return promise;\n }\n}\n"]} -------------------------------------------------------------------------------- /dist/ngx-webworker/fesm2015/nitinkrmr-ngx-webworker.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"nitinkrmr-ngx-webworker.js","sources":["ng://@nitinkrmr/ngx-webworker/lib/webworker.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\ntype CallbackFunction = () => void;\n\n@Injectable()\nexport class WebworkerService {\n private workerFunctionToUrlMap = new WeakMap();\n private promiseToWorkerMap = new WeakMap, Worker>();\n\n run(workerFunction: (input: any) => T, data?: any): Promise {\n const url = this.getOrCreateWorkerUrl(workerFunction);\n return this.runUrl(url, data);\n }\n\n runUrl(url: string, data?: any): Promise {\n const worker = new Worker(url);\n const promise = this.createPromiseForWorker(worker, data);\n const promiseCleaner = this.createPromiseCleaner(promise);\n\n this.promiseToWorkerMap.set(promise, worker);\n\n promise.then(promiseCleaner).catch(promiseCleaner);\n\n return promise;\n }\n\n terminate(promise: Promise): Promise {\n return this.removePromise(promise);\n }\n\n getWorker(promise: Promise): Worker {\n return this.promiseToWorkerMap.get(promise);\n }\n\n private createPromiseForWorker(worker: Worker, data: any) {\n return new Promise((resolve, reject) => {\n worker.addEventListener('message', (event) => resolve(event.data));\n worker.addEventListener('error', reject);\n worker.postMessage(data);\n });\n }\n\n private getOrCreateWorkerUrl(fn: any): string {\n if (!this.workerFunctionToUrlMap.has(fn)) {\n const url = this.createWorkerUrl(fn);\n this.workerFunctionToUrlMap.set(fn, url);\n return url;\n }\n return this.workerFunctionToUrlMap.get(fn);\n }\n\n private createWorkerUrl(resolve: CallbackFunction): string {\n const resolveString = resolve.toString();\n const webWorkerTemplate = `\n self.addEventListener('message', function(e) {\n postMessage((${resolveString})(e.data));\n });\n `;\n const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' });\n return URL.createObjectURL(blob);\n }\n\n private createPromiseCleaner(promise: Promise): (input: any) => T {\n return (event) => {\n this.removePromise(promise);\n return event;\n };\n }\n\n private removePromise(promise: Promise): Promise {\n const worker = this.promiseToWorkerMap.get(promise);\n if (worker) {\n worker.terminate();\n }\n this.promiseToWorkerMap.delete(promise);\n return promise;\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA,MAKa,gBAAgB;IAD7B;QAEU,2BAAsB,GAAG,IAAI,OAAO,EAA4B,CAAC;QACjE,uBAAkB,GAAG,IAAI,OAAO,EAAwB,CAAC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EAAE,CAAC,EAAE;;kBAClC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YACzC,OAAO,GAAG,CAAC;SACZ;QACD,OAAO,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAC5C;;;;;;IAEO,eAAe,CAAC,OAAyB;;cACzC,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;;cAClC,iBAAiB,GAAG;;uBAEP,aAAa;;KAE/B;;cACK,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;QACvE,OAAO,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;KAClC;;;;;;;IAEO,oBAAoB,CAAI,OAAmB;QACjD;;;;QAAO,CAAC,KAAK;YACX,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd,EAAC;KACH;;;;;;;IAEO,aAAa,CAAI,OAAmB;;cACpC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;QACnD,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,SAAS,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;KAChB;;;YAxEF,UAAU;;;;;"} -------------------------------------------------------------------------------- /dist/ngx-webworker/fesm2015/nitinkrmr-ngx-webworker.js: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | /** 4 | * @fileoverview added by tsickle 5 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 6 | */ 7 | class WebworkerService { 8 | constructor() { 9 | this.workerFunctionToUrlMap = new WeakMap(); 10 | this.promiseToWorkerMap = new WeakMap(); 11 | } 12 | /** 13 | * @template T 14 | * @param {?} workerFunction 15 | * @param {?=} data 16 | * @return {?} 17 | */ 18 | run(workerFunction, data) { 19 | /** @type {?} */ 20 | const url = this.getOrCreateWorkerUrl(workerFunction); 21 | return this.runUrl(url, data); 22 | } 23 | /** 24 | * @param {?} url 25 | * @param {?=} data 26 | * @return {?} 27 | */ 28 | runUrl(url, data) { 29 | /** @type {?} */ 30 | const worker = new Worker(url); 31 | /** @type {?} */ 32 | const promise = this.createPromiseForWorker(worker, data); 33 | /** @type {?} */ 34 | const promiseCleaner = this.createPromiseCleaner(promise); 35 | this.promiseToWorkerMap.set(promise, worker); 36 | promise.then(promiseCleaner).catch(promiseCleaner); 37 | return promise; 38 | } 39 | /** 40 | * @template T 41 | * @param {?} promise 42 | * @return {?} 43 | */ 44 | terminate(promise) { 45 | return this.removePromise(promise); 46 | } 47 | /** 48 | * @param {?} promise 49 | * @return {?} 50 | */ 51 | getWorker(promise) { 52 | return this.promiseToWorkerMap.get(promise); 53 | } 54 | /** 55 | * @private 56 | * @template T 57 | * @param {?} worker 58 | * @param {?} data 59 | * @return {?} 60 | */ 61 | createPromiseForWorker(worker, data) { 62 | return new Promise((/** 63 | * @param {?} resolve 64 | * @param {?} reject 65 | * @return {?} 66 | */ 67 | (resolve, reject) => { 68 | worker.addEventListener('message', (/** 69 | * @param {?} event 70 | * @return {?} 71 | */ 72 | (event) => resolve(event.data))); 73 | worker.addEventListener('error', reject); 74 | worker.postMessage(data); 75 | })); 76 | } 77 | /** 78 | * @private 79 | * @param {?} fn 80 | * @return {?} 81 | */ 82 | getOrCreateWorkerUrl(fn) { 83 | if (!this.workerFunctionToUrlMap.has(fn)) { 84 | /** @type {?} */ 85 | const url = this.createWorkerUrl(fn); 86 | this.workerFunctionToUrlMap.set(fn, url); 87 | return url; 88 | } 89 | return this.workerFunctionToUrlMap.get(fn); 90 | } 91 | /** 92 | * @private 93 | * @param {?} resolve 94 | * @return {?} 95 | */ 96 | createWorkerUrl(resolve) { 97 | /** @type {?} */ 98 | const resolveString = resolve.toString(); 99 | /** @type {?} */ 100 | const webWorkerTemplate = ` 101 | self.addEventListener('message', function(e) { 102 | postMessage((${resolveString})(e.data)); 103 | }); 104 | `; 105 | /** @type {?} */ 106 | const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 107 | return URL.createObjectURL(blob); 108 | } 109 | /** 110 | * @private 111 | * @template T 112 | * @param {?} promise 113 | * @return {?} 114 | */ 115 | createPromiseCleaner(promise) { 116 | return (/** 117 | * @param {?} event 118 | * @return {?} 119 | */ 120 | (event) => { 121 | this.removePromise(promise); 122 | return event; 123 | }); 124 | } 125 | /** 126 | * @private 127 | * @template T 128 | * @param {?} promise 129 | * @return {?} 130 | */ 131 | removePromise(promise) { 132 | /** @type {?} */ 133 | const worker = this.promiseToWorkerMap.get(promise); 134 | if (worker) { 135 | worker.terminate(); 136 | } 137 | this.promiseToWorkerMap.delete(promise); 138 | return promise; 139 | } 140 | } 141 | WebworkerService.decorators = [ 142 | { type: Injectable } 143 | ]; 144 | 145 | export { WebworkerService }; 146 | //# sourceMappingURL=nitinkrmr-ngx-webworker.js.map 147 | -------------------------------------------------------------------------------- /dist/ngx-webworker/fesm5/nitinkrmr-ngx-webworker.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"nitinkrmr-ngx-webworker.js","sources":["ng://@nitinkrmr/ngx-webworker/lib/webworker.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\ntype CallbackFunction = () => void;\n\n@Injectable()\nexport class WebworkerService {\n private workerFunctionToUrlMap = new WeakMap();\n private promiseToWorkerMap = new WeakMap, Worker>();\n\n run(workerFunction: (input: any) => T, data?: any): Promise {\n const url = this.getOrCreateWorkerUrl(workerFunction);\n return this.runUrl(url, data);\n }\n\n runUrl(url: string, data?: any): Promise {\n const worker = new Worker(url);\n const promise = this.createPromiseForWorker(worker, data);\n const promiseCleaner = this.createPromiseCleaner(promise);\n\n this.promiseToWorkerMap.set(promise, worker);\n\n promise.then(promiseCleaner).catch(promiseCleaner);\n\n return promise;\n }\n\n terminate(promise: Promise): Promise {\n return this.removePromise(promise);\n }\n\n getWorker(promise: Promise): Worker {\n return this.promiseToWorkerMap.get(promise);\n }\n\n private createPromiseForWorker(worker: Worker, data: any) {\n return new Promise((resolve, reject) => {\n worker.addEventListener('message', (event) => resolve(event.data));\n worker.addEventListener('error', reject);\n worker.postMessage(data);\n });\n }\n\n private getOrCreateWorkerUrl(fn: any): string {\n if (!this.workerFunctionToUrlMap.has(fn)) {\n const url = this.createWorkerUrl(fn);\n this.workerFunctionToUrlMap.set(fn, url);\n return url;\n }\n return this.workerFunctionToUrlMap.get(fn);\n }\n\n private createWorkerUrl(resolve: CallbackFunction): string {\n const resolveString = resolve.toString();\n const webWorkerTemplate = `\n self.addEventListener('message', function(e) {\n postMessage((${resolveString})(e.data));\n });\n `;\n const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' });\n return URL.createObjectURL(blob);\n }\n\n private createPromiseCleaner(promise: Promise): (input: any) => T {\n return (event) => {\n this.removePromise(promise);\n return event;\n };\n }\n\n private removePromise(promise: Promise): Promise {\n const worker = this.promiseToWorkerMap.get(promise);\n if (worker) {\n worker.terminate();\n }\n this.promiseToWorkerMap.delete(promise);\n return promise;\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;IAIA;QAEU,2BAAsB,GAAG,IAAI,OAAO,EAA4B,CAAC;QACjE,uBAAkB,GAAG,IAAI,OAAO,EAAwB,CAAC;KAsElE;;;;;;;IApEC,8BAAG;;;;;;IAAH,UAAO,cAAiC,EAAE,IAAU;;YAC5C,GAAG,GAAG,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KAC/B;;;;;;IAED,iCAAM;;;;;IAAN,UAAO,GAAW,EAAE,IAAU;;YACtB,MAAM,GAAG,IAAI,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O,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAC5C;;;;;;IAEO,0CAAe;;;;;IAAvB,UAAwB,OAAyB;;YACzC,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;;YAClC,iBAAiB,GAAG,kFAEP,aAAa,iCAE/B;;YACK,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;QACvE,OAAO,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;KAClC;;;;;;;IAEO,+CAAoB;;;;;;IAA5B,UAAgC,OAAmB;QAAnD,iBAKC;QAJC;;;;QAAO,UAAC,KAAK;YACX,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd,EAAC;KACH;;;;;;;IAEO,wCAAa;;;;;;IAArB,UAAyB,OAAmB;;YACpC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;QACnD,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,SAAS,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;KAChB;;gBAxEF,UAAU;;IAyEX,uBAAC;CAzED;;;;"} -------------------------------------------------------------------------------- /dist/ngx-webworker/bundles/nitinkrmr-ngx-webworker.umd.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"nitinkrmr-ngx-webworker.umd.js","sources":["ng://@nitinkrmr/ngx-webworker/lib/webworker.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\ntype CallbackFunction = () => void;\n\n@Injectable()\nexport class WebworkerService {\n private workerFunctionToUrlMap = new WeakMap();\n private promiseToWorkerMap = new WeakMap, Worker>();\n\n run(workerFunction: (input: any) => T, data?: any): Promise {\n const url = this.getOrCreateWorkerUrl(workerFunction);\n return this.runUrl(url, data);\n }\n\n runUrl(url: string, data?: any): Promise {\n const worker = new Worker(url);\n const promise = this.createPromiseForWorker(worker, data);\n const promiseCleaner = this.createPromiseCleaner(promise);\n\n this.promiseToWorkerMap.set(promise, worker);\n\n promise.then(promiseCleaner).catch(promiseCleaner);\n\n return promise;\n }\n\n terminate(promise: Promise): Promise {\n return this.removePromise(promise);\n }\n\n getWorker(promise: Promise): Worker {\n return this.promiseToWorkerMap.get(promise);\n }\n\n private createPromiseForWorker(worker: Worker, data: any) {\n return new Promise((resolve, reject) => {\n worker.addEventListener('message', (event) => resolve(event.data));\n worker.addEventListener('error', reject);\n worker.postMessage(data);\n });\n }\n\n private getOrCreateWorkerUrl(fn: any): string {\n if (!this.workerFunctionToUrlMap.has(fn)) {\n const url = this.createWorkerUrl(fn);\n this.workerFunctionToUrlMap.set(fn, url);\n return url;\n }\n return this.workerFunctionToUrlMap.get(fn);\n }\n\n private createWorkerUrl(resolve: CallbackFunction): string {\n const resolveString = resolve.toString();\n const webWorkerTemplate = `\n self.addEventListener('message', function(e) {\n postMessage((${resolveString})(e.data));\n });\n `;\n const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' });\n return URL.createObjectURL(blob);\n }\n\n private createPromiseCleaner(promise: Promise): (input: any) => T {\n return (event) => {\n this.removePromise(promise);\n return event;\n };\n }\n\n private removePromise(promise: Promise): Promise {\n const worker = this.promiseToWorkerMap.get(promise);\n if (worker) {\n worker.terminate();\n }\n this.promiseToWorkerMap.delete(promise);\n return promise;\n }\n}\n"],"names":["Injectable"],"mappings":";;;;;;;;;;AAAA;QAIA;YAEU,2BAAsB,GAAG,IAAI,OAAO,EAA4B,CAAC;YACjE,uBAAkB,GAAG,IAAI,OAAO,EAAwB,CAAC;SAsElE;;;;;;;QApEC,8BAAG;;;;;;QAAH,UAAO,cAAiC,EAAE,IAAU;;gBAC5C,GAAG,GAAG,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC;YACrD,OAAO,IAAI,CAAC,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AAe,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACzC,OAAO,GAAG,CAAC;aACZ;YACD,OAAO,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC5C;;;;;;QAEO,0CAAe;;;;;QAAvB,UAAwB,OAAyB;;gBACzC,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;;gBAClC,iBAAiB,GAAG,kFAEP,aAAa,iCAE/B;;gBACK,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;YACvE,OAAO,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAClC;;;;;;;QAEO,+CAAoB;;;;;;QAA5B,UAAgC,OAAmB;YAAnD,iBAKC;YAJC;;;;YAAO,UAAC,KAAK;gBACX,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;gBAC5B,OAAO,KAAK,CAAC;aACd,EAAC;SACH;;;;;;;QAEO,wCAAa;;;;;;QAArB,UAAyB,OAAmB;;gBACpC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;YACnD,IAAI,MAAM,EAAE;gBACV,MAAM,CAAC,SAAS,EAAE,CAAC;aACpB;YACD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxC,OAAO,OAAO,CAAC;SAChB;;oBAxEFA,eAAU;;QAyEX,uBAAC;KAzED;;;;;;;;;;;;"} -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "web-wroker-tester": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "projects/web-wroker-tester", 10 | "sourceRoot": "projects/web-wroker-tester/src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/web-wroker-tester", 17 | "index": "projects/web-wroker-tester/src/index.html", 18 | "main": "projects/web-wroker-tester/src/main.ts", 19 | "polyfills": "projects/web-wroker-tester/src/polyfills.ts", 20 | "tsConfig": "projects/web-wroker-tester/tsconfig.app.json", 21 | "aot": false, 22 | "assets": [ 23 | "projects/web-wroker-tester/src/favicon.ico", 24 | "projects/web-wroker-tester/src/assets" 25 | ], 26 | "styles": ["projects/web-wroker-tester/src/styles.css"], 27 | "scripts": [] 28 | }, 29 | "configurations": { 30 | "production": { 31 | "fileReplacements": [ 32 | { 33 | "replace": "projects/web-wroker-tester/src/environments/environment.ts", 34 | "with": "projects/web-wroker-tester/src/environments/environment.prod.ts" 35 | } 36 | ], 37 | "optimization": true, 38 | "outputHashing": "all", 39 | "sourceMap": false, 40 | "extractCss": true, 41 | "namedChunks": false, 42 | "aot": true, 43 | "extractLicenses": true, 44 | "vendorChunk": false, 45 | "buildOptimizer": true, 46 | "budgets": [ 47 | { 48 | "type": "initial", 49 | "maximumWarning": "2mb", 50 | "maximumError": "5mb" 51 | } 52 | ] 53 | } 54 | } 55 | }, 56 | "serve": { 57 | "builder": "@angular-devkit/build-angular:dev-server", 58 | "options": { 59 | "browserTarget": "web-wroker-tester:build" 60 | }, 61 | "configurations": { 62 | "production": { 63 | "browserTarget": "web-wroker-tester:build:production" 64 | } 65 | } 66 | }, 67 | "extract-i18n": { 68 | "builder": "@angular-devkit/build-angular:extract-i18n", 69 | "options": { 70 | "browserTarget": "web-wroker-tester:build" 71 | } 72 | }, 73 | "test": { 74 | "builder": "@angular-devkit/build-angular:karma", 75 | "options": { 76 | "main": "projects/web-wroker-tester/src/test.ts", 77 | "polyfills": "projects/web-wroker-tester/src/polyfills.ts", 78 | "tsConfig": "projects/web-wroker-tester/tsconfig.spec.json", 79 | "karmaConfig": "projects/web-wroker-tester/karma.conf.js", 80 | "assets": [ 81 | "projects/web-wroker-tester/src/favicon.ico", 82 | "projects/web-wroker-tester/src/assets" 83 | ], 84 | "styles": ["projects/web-wroker-tester/src/styles.css"], 85 | "scripts": [] 86 | } 87 | }, 88 | "lint": { 89 | "builder": "@angular-devkit/build-angular:tslint", 90 | "options": { 91 | "tsConfig": [ 92 | "projects/web-wroker-tester/tsconfig.app.json", 93 | "projects/web-wroker-tester/tsconfig.spec.json", 94 | "projects/web-wroker-tester/e2e/tsconfig.json" 95 | ], 96 | "exclude": ["**/node_modules/**"] 97 | } 98 | }, 99 | "e2e": { 100 | "builder": "@angular-devkit/build-angular:protractor", 101 | "options": { 102 | "protractorConfig": "projects/web-wroker-tester/e2e/protractor.conf.js", 103 | "devServerTarget": "web-wroker-tester:serve" 104 | }, 105 | "configurations": { 106 | "production": { 107 | "devServerTarget": "web-wroker-tester:serve:production" 108 | } 109 | } 110 | } 111 | } 112 | }, 113 | "ngx-webworker": { 114 | "projectType": "library", 115 | "root": "projects/ngx-webworker", 116 | "sourceRoot": "projects/ngx-webworker/src", 117 | "prefix": "lib", 118 | "architect": { 119 | "build": { 120 | "builder": "@angular-devkit/build-ng-packagr:build", 121 | "options": { 122 | "tsConfig": "projects/ngx-webworker/tsconfig.lib.json", 123 | "project": "projects/ngx-webworker/ng-package.json" 124 | } 125 | }, 126 | "test": { 127 | "builder": "@angular-devkit/build-angular:karma", 128 | "options": { 129 | "main": "projects/ngx-webworker/src/test.ts", 130 | "tsConfig": "projects/ngx-webworker/tsconfig.spec.json", 131 | "karmaConfig": "projects/ngx-webworker/karma.conf.js" 132 | } 133 | }, 134 | "lint": { 135 | "builder": "@angular-devkit/build-angular:tslint", 136 | "options": { 137 | "tsConfig": [ 138 | "projects/ngx-webworker/tsconfig.lib.json", 139 | "projects/ngx-webworker/tsconfig.spec.json" 140 | ], 141 | "exclude": ["**/node_modules/**"] 142 | } 143 | } 144 | } 145 | } 146 | }, 147 | "defaultProject": "ngx-webworker-tester" 148 | } 149 | -------------------------------------------------------------------------------- /dist/ngx-webworker/fesm5/nitinkrmr-ngx-webworker.js: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | /** 4 | * @fileoverview added by tsickle 5 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 6 | */ 7 | var WebworkerService = /** @class */ (function () { 8 | function WebworkerService() { 9 | this.workerFunctionToUrlMap = new WeakMap(); 10 | this.promiseToWorkerMap = new WeakMap(); 11 | } 12 | /** 13 | * @template T 14 | * @param {?} workerFunction 15 | * @param {?=} data 16 | * @return {?} 17 | */ 18 | WebworkerService.prototype.run = /** 19 | * @template T 20 | * @param {?} workerFunction 21 | * @param {?=} data 22 | * @return {?} 23 | */ 24 | function (workerFunction, data) { 25 | /** @type {?} */ 26 | var url = this.getOrCreateWorkerUrl(workerFunction); 27 | return this.runUrl(url, data); 28 | }; 29 | /** 30 | * @param {?} url 31 | * @param {?=} data 32 | * @return {?} 33 | */ 34 | WebworkerService.prototype.runUrl = /** 35 | * @param {?} url 36 | * @param {?=} data 37 | * @return {?} 38 | */ 39 | function (url, data) { 40 | /** @type {?} */ 41 | var worker = new Worker(url); 42 | /** @type {?} */ 43 | var promise = this.createPromiseForWorker(worker, data); 44 | /** @type {?} */ 45 | var promiseCleaner = this.createPromiseCleaner(promise); 46 | this.promiseToWorkerMap.set(promise, worker); 47 | promise.then(promiseCleaner).catch(promiseCleaner); 48 | return promise; 49 | }; 50 | /** 51 | * @template T 52 | * @param {?} promise 53 | * @return {?} 54 | */ 55 | WebworkerService.prototype.terminate = /** 56 | * @template T 57 | * @param {?} promise 58 | * @return {?} 59 | */ 60 | function (promise) { 61 | return this.removePromise(promise); 62 | }; 63 | /** 64 | * @param {?} promise 65 | * @return {?} 66 | */ 67 | WebworkerService.prototype.getWorker = /** 68 | * @param {?} promise 69 | * @return {?} 70 | */ 71 | function (promise) { 72 | return this.promiseToWorkerMap.get(promise); 73 | }; 74 | /** 75 | * @private 76 | * @template T 77 | * @param {?} worker 78 | * @param {?} data 79 | * @return {?} 80 | */ 81 | WebworkerService.prototype.createPromiseForWorker = /** 82 | * @private 83 | * @template T 84 | * @param {?} worker 85 | * @param {?} data 86 | * @return {?} 87 | */ 88 | function (worker, data) { 89 | return new Promise((/** 90 | * @param {?} resolve 91 | * @param {?} reject 92 | * @return {?} 93 | */ 94 | function (resolve, reject) { 95 | worker.addEventListener('message', (/** 96 | * @param {?} event 97 | * @return {?} 98 | */ 99 | function (event) { return resolve(event.data); })); 100 | worker.addEventListener('error', reject); 101 | worker.postMessage(data); 102 | })); 103 | }; 104 | /** 105 | * @private 106 | * @param {?} fn 107 | * @return {?} 108 | */ 109 | WebworkerService.prototype.getOrCreateWorkerUrl = /** 110 | * @private 111 | * @param {?} fn 112 | * @return {?} 113 | */ 114 | function (fn) { 115 | if (!this.workerFunctionToUrlMap.has(fn)) { 116 | /** @type {?} */ 117 | var url = this.createWorkerUrl(fn); 118 | this.workerFunctionToUrlMap.set(fn, url); 119 | return url; 120 | } 121 | return this.workerFunctionToUrlMap.get(fn); 122 | }; 123 | /** 124 | * @private 125 | * @param {?} resolve 126 | * @return {?} 127 | */ 128 | WebworkerService.prototype.createWorkerUrl = /** 129 | * @private 130 | * @param {?} resolve 131 | * @return {?} 132 | */ 133 | function (resolve) { 134 | /** @type {?} */ 135 | var resolveString = resolve.toString(); 136 | /** @type {?} */ 137 | var webWorkerTemplate = "\n self.addEventListener('message', function(e) {\n postMessage((" + resolveString + ")(e.data));\n });\n "; 138 | /** @type {?} */ 139 | var blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 140 | return URL.createObjectURL(blob); 141 | }; 142 | /** 143 | * @private 144 | * @template T 145 | * @param {?} promise 146 | * @return {?} 147 | */ 148 | WebworkerService.prototype.createPromiseCleaner = /** 149 | * @private 150 | * @template T 151 | * @param {?} promise 152 | * @return {?} 153 | */ 154 | function (promise) { 155 | var _this = this; 156 | return (/** 157 | * @param {?} event 158 | * @return {?} 159 | */ 160 | function (event) { 161 | _this.removePromise(promise); 162 | return event; 163 | }); 164 | }; 165 | /** 166 | * @private 167 | * @template T 168 | * @param {?} promise 169 | * @return {?} 170 | */ 171 | WebworkerService.prototype.removePromise = /** 172 | * @private 173 | * @template T 174 | * @param {?} promise 175 | * @return {?} 176 | */ 177 | function (promise) { 178 | /** @type {?} */ 179 | var worker = this.promiseToWorkerMap.get(promise); 180 | if (worker) { 181 | worker.terminate(); 182 | } 183 | this.promiseToWorkerMap.delete(promise); 184 | return promise; 185 | }; 186 | WebworkerService.decorators = [ 187 | { type: Injectable } 188 | ]; 189 | return WebworkerService; 190 | }()); 191 | 192 | export { WebworkerService }; 193 | //# sourceMappingURL=nitinkrmr-ngx-webworker.js.map 194 | -------------------------------------------------------------------------------- /dist/web-wroker-tester/runtime-es5.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/bootstrap"],"names":[],"mappings":";AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,gBAAQ,oBAAoB;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,yBAAiB,4BAA4B;AAC7C;AACA;AACA,0BAAkB,2BAA2B;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;AACA;AACA;AACA,wBAAgB,uBAAuB;AACvC;;;AAGA;AACA","file":"runtime-es5.js","sourcesContent":[" \t// install a JSONP callback for chunk loading\n \tfunction webpackJsonpCallback(data) {\n \t\tvar chunkIds = data[0];\n \t\tvar moreModules = data[1];\n \t\tvar executeModules = data[2];\n\n \t\t// add \"moreModules\" to the modules object,\n \t\t// then flag all \"chunkIds\" as loaded and fire callback\n \t\tvar moduleId, chunkId, i = 0, resolves = [];\n \t\tfor(;i < chunkIds.length; i++) {\n \t\t\tchunkId = chunkIds[i];\n \t\t\tif(installedChunks[chunkId]) {\n \t\t\t\tresolves.push(installedChunks[chunkId][0]);\n \t\t\t}\n \t\t\tinstalledChunks[chunkId] = 0;\n \t\t}\n \t\tfor(moduleId in moreModules) {\n \t\t\tif(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {\n \t\t\t\tmodules[moduleId] = moreModules[moduleId];\n \t\t\t}\n \t\t}\n \t\tif(parentJsonpFunction) parentJsonpFunction(data);\n\n \t\twhile(resolves.length) {\n \t\t\tresolves.shift()();\n \t\t}\n\n \t\t// add entry modules from loaded chunk to deferred list\n \t\tdeferredModules.push.apply(deferredModules, executeModules || []);\n\n \t\t// run deferred modules when all chunks ready\n \t\treturn checkDeferredModules();\n \t};\n \tfunction checkDeferredModules() {\n \t\tvar result;\n \t\tfor(var i = 0; i < deferredModules.length; i++) {\n \t\t\tvar deferredModule = deferredModules[i];\n \t\t\tvar fulfilled = true;\n \t\t\tfor(var j = 1; j < deferredModule.length; j++) {\n \t\t\t\tvar depId = deferredModule[j];\n \t\t\t\tif(installedChunks[depId] !== 0) fulfilled = false;\n \t\t\t}\n \t\t\tif(fulfilled) {\n \t\t\t\tdeferredModules.splice(i--, 1);\n \t\t\t\tresult = __webpack_require__(__webpack_require__.s = deferredModule[0]);\n \t\t\t}\n \t\t}\n \t\treturn result;\n \t}\n\n \t// The module cache\n \tvar installedModules = {};\n\n \t// object to store loaded and loading chunks\n \t// undefined = chunk not loaded, null = chunk preloaded/prefetched\n \t// Promise = chunk loading, 0 = chunk loaded\n \tvar installedChunks = {\n \t\t\"runtime\": 0\n \t};\n\n \tvar deferredModules = [];\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 \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\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.l = 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// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \tvar jsonpArray = window[\"webpackJsonp\"] = window[\"webpackJsonp\"] || [];\n \tvar oldJsonpFunction = jsonpArray.push.bind(jsonpArray);\n \tjsonpArray.push = webpackJsonpCallback;\n \tjsonpArray = jsonpArray.slice();\n \tfor(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);\n \tvar parentJsonpFunction = oldJsonpFunction;\n\n\n \t// run deferred modules from other chunks\n \tcheckDeferredModules();\n"],"sourceRoot":""} -------------------------------------------------------------------------------- /dist/web-wroker-tester/runtime-es2015.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/bootstrap"],"names":[],"mappings":";AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,gBAAQ,oBAAoB;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,yBAAiB,4BAA4B;AAC7C;AACA;AACA,0BAAkB,2BAA2B;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;AACA;AACA;AACA,wBAAgB,uBAAuB;AACvC;;;AAGA;AACA","file":"runtime-es2015.js","sourcesContent":[" \t// install a JSONP callback for chunk loading\n \tfunction webpackJsonpCallback(data) {\n \t\tvar chunkIds = data[0];\n \t\tvar moreModules = data[1];\n \t\tvar executeModules = data[2];\n\n \t\t// add \"moreModules\" to the modules object,\n \t\t// then flag all \"chunkIds\" as loaded and fire callback\n \t\tvar moduleId, chunkId, i = 0, resolves = [];\n \t\tfor(;i < chunkIds.length; i++) {\n \t\t\tchunkId = chunkIds[i];\n \t\t\tif(installedChunks[chunkId]) {\n \t\t\t\tresolves.push(installedChunks[chunkId][0]);\n \t\t\t}\n \t\t\tinstalledChunks[chunkId] = 0;\n \t\t}\n \t\tfor(moduleId in moreModules) {\n \t\t\tif(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {\n \t\t\t\tmodules[moduleId] = moreModules[moduleId];\n \t\t\t}\n \t\t}\n \t\tif(parentJsonpFunction) parentJsonpFunction(data);\n\n \t\twhile(resolves.length) {\n \t\t\tresolves.shift()();\n \t\t}\n\n \t\t// add entry modules from loaded chunk to deferred list\n \t\tdeferredModules.push.apply(deferredModules, executeModules || []);\n\n \t\t// run deferred modules when all chunks ready\n \t\treturn checkDeferredModules();\n \t};\n \tfunction checkDeferredModules() {\n \t\tvar result;\n \t\tfor(var i = 0; i < deferredModules.length; i++) {\n \t\t\tvar deferredModule = deferredModules[i];\n \t\t\tvar fulfilled = true;\n \t\t\tfor(var j = 1; j < deferredModule.length; j++) {\n \t\t\t\tvar depId = deferredModule[j];\n \t\t\t\tif(installedChunks[depId] !== 0) fulfilled = false;\n \t\t\t}\n \t\t\tif(fulfilled) {\n \t\t\t\tdeferredModules.splice(i--, 1);\n \t\t\t\tresult = __webpack_require__(__webpack_require__.s = deferredModule[0]);\n \t\t\t}\n \t\t}\n \t\treturn result;\n \t}\n\n \t// The module cache\n \tvar installedModules = {};\n\n \t// object to store loaded and loading chunks\n \t// undefined = chunk not loaded, null = chunk preloaded/prefetched\n \t// Promise = chunk loading, 0 = chunk loaded\n \tvar installedChunks = {\n \t\t\"runtime\": 0\n \t};\n\n \tvar deferredModules = [];\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 \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\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.l = 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// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \tvar jsonpArray = window[\"webpackJsonp\"] = window[\"webpackJsonp\"] || [];\n \tvar oldJsonpFunction = jsonpArray.push.bind(jsonpArray);\n \tjsonpArray.push = webpackJsonpCallback;\n \tjsonpArray = jsonpArray.slice();\n \tfor(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);\n \tvar parentJsonpFunction = oldJsonpFunction;\n\n\n \t// run deferred modules from other chunks\n \tcheckDeferredModules();\n"],"sourceRoot":""} -------------------------------------------------------------------------------- /dist/web-wroker-tester/runtime-es5.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // install a JSONP callback for chunk loading 3 | /******/ function webpackJsonpCallback(data) { 4 | /******/ var chunkIds = data[0]; 5 | /******/ var moreModules = data[1]; 6 | /******/ var executeModules = data[2]; 7 | /******/ 8 | /******/ // add "moreModules" to the modules object, 9 | /******/ // then flag all "chunkIds" as loaded and fire callback 10 | /******/ var moduleId, chunkId, i = 0, resolves = []; 11 | /******/ for(;i < chunkIds.length; i++) { 12 | /******/ chunkId = chunkIds[i]; 13 | /******/ if(installedChunks[chunkId]) { 14 | /******/ resolves.push(installedChunks[chunkId][0]); 15 | /******/ } 16 | /******/ installedChunks[chunkId] = 0; 17 | /******/ } 18 | /******/ for(moduleId in moreModules) { 19 | /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { 20 | /******/ modules[moduleId] = moreModules[moduleId]; 21 | /******/ } 22 | /******/ } 23 | /******/ if(parentJsonpFunction) parentJsonpFunction(data); 24 | /******/ 25 | /******/ while(resolves.length) { 26 | /******/ resolves.shift()(); 27 | /******/ } 28 | /******/ 29 | /******/ // add entry modules from loaded chunk to deferred list 30 | /******/ deferredModules.push.apply(deferredModules, executeModules || []); 31 | /******/ 32 | /******/ // run deferred modules when all chunks ready 33 | /******/ return checkDeferredModules(); 34 | /******/ }; 35 | /******/ function checkDeferredModules() { 36 | /******/ var result; 37 | /******/ for(var i = 0; i < deferredModules.length; i++) { 38 | /******/ var deferredModule = deferredModules[i]; 39 | /******/ var fulfilled = true; 40 | /******/ for(var j = 1; j < deferredModule.length; j++) { 41 | /******/ var depId = deferredModule[j]; 42 | /******/ if(installedChunks[depId] !== 0) fulfilled = false; 43 | /******/ } 44 | /******/ if(fulfilled) { 45 | /******/ deferredModules.splice(i--, 1); 46 | /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); 47 | /******/ } 48 | /******/ } 49 | /******/ return result; 50 | /******/ } 51 | /******/ 52 | /******/ // The module cache 53 | /******/ var installedModules = {}; 54 | /******/ 55 | /******/ // object to store loaded and loading chunks 56 | /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched 57 | /******/ // Promise = chunk loading, 0 = chunk loaded 58 | /******/ var installedChunks = { 59 | /******/ "runtime": 0 60 | /******/ }; 61 | /******/ 62 | /******/ var deferredModules = []; 63 | /******/ 64 | /******/ // The require function 65 | /******/ function __webpack_require__(moduleId) { 66 | /******/ 67 | /******/ // Check if module is in cache 68 | /******/ if(installedModules[moduleId]) { 69 | /******/ return installedModules[moduleId].exports; 70 | /******/ } 71 | /******/ // Create a new module (and put it into the cache) 72 | /******/ var module = installedModules[moduleId] = { 73 | /******/ i: moduleId, 74 | /******/ l: false, 75 | /******/ exports: {} 76 | /******/ }; 77 | /******/ 78 | /******/ // Execute the module function 79 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 80 | /******/ 81 | /******/ // Flag the module as loaded 82 | /******/ module.l = true; 83 | /******/ 84 | /******/ // Return the exports of the module 85 | /******/ return module.exports; 86 | /******/ } 87 | /******/ 88 | /******/ 89 | /******/ // expose the modules object (__webpack_modules__) 90 | /******/ __webpack_require__.m = modules; 91 | /******/ 92 | /******/ // expose the module cache 93 | /******/ __webpack_require__.c = installedModules; 94 | /******/ 95 | /******/ // define getter function for harmony exports 96 | /******/ __webpack_require__.d = function(exports, name, getter) { 97 | /******/ if(!__webpack_require__.o(exports, name)) { 98 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 99 | /******/ } 100 | /******/ }; 101 | /******/ 102 | /******/ // define __esModule on exports 103 | /******/ __webpack_require__.r = function(exports) { 104 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 105 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 106 | /******/ } 107 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 108 | /******/ }; 109 | /******/ 110 | /******/ // create a fake namespace object 111 | /******/ // mode & 1: value is a module id, require it 112 | /******/ // mode & 2: merge all properties of value into the ns 113 | /******/ // mode & 4: return value when already ns object 114 | /******/ // mode & 8|1: behave like require 115 | /******/ __webpack_require__.t = function(value, mode) { 116 | /******/ if(mode & 1) value = __webpack_require__(value); 117 | /******/ if(mode & 8) return value; 118 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 119 | /******/ var ns = Object.create(null); 120 | /******/ __webpack_require__.r(ns); 121 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 122 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 123 | /******/ return ns; 124 | /******/ }; 125 | /******/ 126 | /******/ // getDefaultExport function for compatibility with non-harmony modules 127 | /******/ __webpack_require__.n = function(module) { 128 | /******/ var getter = module && module.__esModule ? 129 | /******/ function getDefault() { return module['default']; } : 130 | /******/ function getModuleExports() { return module; }; 131 | /******/ __webpack_require__.d(getter, 'a', getter); 132 | /******/ return getter; 133 | /******/ }; 134 | /******/ 135 | /******/ // Object.prototype.hasOwnProperty.call 136 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 137 | /******/ 138 | /******/ // __webpack_public_path__ 139 | /******/ __webpack_require__.p = ""; 140 | /******/ 141 | /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; 142 | /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); 143 | /******/ jsonpArray.push = webpackJsonpCallback; 144 | /******/ jsonpArray = jsonpArray.slice(); 145 | /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); 146 | /******/ var parentJsonpFunction = oldJsonpFunction; 147 | /******/ 148 | /******/ 149 | /******/ // run deferred modules from other chunks 150 | /******/ checkDeferredModules(); 151 | /******/ }) 152 | /************************************************************************/ 153 | /******/ ([]); 154 | //# sourceMappingURL=runtime-es5.js.map -------------------------------------------------------------------------------- /dist/web-wroker-tester/runtime-es2015.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // install a JSONP callback for chunk loading 3 | /******/ function webpackJsonpCallback(data) { 4 | /******/ var chunkIds = data[0]; 5 | /******/ var moreModules = data[1]; 6 | /******/ var executeModules = data[2]; 7 | /******/ 8 | /******/ // add "moreModules" to the modules object, 9 | /******/ // then flag all "chunkIds" as loaded and fire callback 10 | /******/ var moduleId, chunkId, i = 0, resolves = []; 11 | /******/ for(;i < chunkIds.length; i++) { 12 | /******/ chunkId = chunkIds[i]; 13 | /******/ if(installedChunks[chunkId]) { 14 | /******/ resolves.push(installedChunks[chunkId][0]); 15 | /******/ } 16 | /******/ installedChunks[chunkId] = 0; 17 | /******/ } 18 | /******/ for(moduleId in moreModules) { 19 | /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { 20 | /******/ modules[moduleId] = moreModules[moduleId]; 21 | /******/ } 22 | /******/ } 23 | /******/ if(parentJsonpFunction) parentJsonpFunction(data); 24 | /******/ 25 | /******/ while(resolves.length) { 26 | /******/ resolves.shift()(); 27 | /******/ } 28 | /******/ 29 | /******/ // add entry modules from loaded chunk to deferred list 30 | /******/ deferredModules.push.apply(deferredModules, executeModules || []); 31 | /******/ 32 | /******/ // run deferred modules when all chunks ready 33 | /******/ return checkDeferredModules(); 34 | /******/ }; 35 | /******/ function checkDeferredModules() { 36 | /******/ var result; 37 | /******/ for(var i = 0; i < deferredModules.length; i++) { 38 | /******/ var deferredModule = deferredModules[i]; 39 | /******/ var fulfilled = true; 40 | /******/ for(var j = 1; j < deferredModule.length; j++) { 41 | /******/ var depId = deferredModule[j]; 42 | /******/ if(installedChunks[depId] !== 0) fulfilled = false; 43 | /******/ } 44 | /******/ if(fulfilled) { 45 | /******/ deferredModules.splice(i--, 1); 46 | /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); 47 | /******/ } 48 | /******/ } 49 | /******/ return result; 50 | /******/ } 51 | /******/ 52 | /******/ // The module cache 53 | /******/ var installedModules = {}; 54 | /******/ 55 | /******/ // object to store loaded and loading chunks 56 | /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched 57 | /******/ // Promise = chunk loading, 0 = chunk loaded 58 | /******/ var installedChunks = { 59 | /******/ "runtime": 0 60 | /******/ }; 61 | /******/ 62 | /******/ var deferredModules = []; 63 | /******/ 64 | /******/ // The require function 65 | /******/ function __webpack_require__(moduleId) { 66 | /******/ 67 | /******/ // Check if module is in cache 68 | /******/ if(installedModules[moduleId]) { 69 | /******/ return installedModules[moduleId].exports; 70 | /******/ } 71 | /******/ // Create a new module (and put it into the cache) 72 | /******/ var module = installedModules[moduleId] = { 73 | /******/ i: moduleId, 74 | /******/ l: false, 75 | /******/ exports: {} 76 | /******/ }; 77 | /******/ 78 | /******/ // Execute the module function 79 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 80 | /******/ 81 | /******/ // Flag the module as loaded 82 | /******/ module.l = true; 83 | /******/ 84 | /******/ // Return the exports of the module 85 | /******/ return module.exports; 86 | /******/ } 87 | /******/ 88 | /******/ 89 | /******/ // expose the modules object (__webpack_modules__) 90 | /******/ __webpack_require__.m = modules; 91 | /******/ 92 | /******/ // expose the module cache 93 | /******/ __webpack_require__.c = installedModules; 94 | /******/ 95 | /******/ // define getter function for harmony exports 96 | /******/ __webpack_require__.d = function(exports, name, getter) { 97 | /******/ if(!__webpack_require__.o(exports, name)) { 98 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 99 | /******/ } 100 | /******/ }; 101 | /******/ 102 | /******/ // define __esModule on exports 103 | /******/ __webpack_require__.r = function(exports) { 104 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 105 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 106 | /******/ } 107 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 108 | /******/ }; 109 | /******/ 110 | /******/ // create a fake namespace object 111 | /******/ // mode & 1: value is a module id, require it 112 | /******/ // mode & 2: merge all properties of value into the ns 113 | /******/ // mode & 4: return value when already ns object 114 | /******/ // mode & 8|1: behave like require 115 | /******/ __webpack_require__.t = function(value, mode) { 116 | /******/ if(mode & 1) value = __webpack_require__(value); 117 | /******/ if(mode & 8) return value; 118 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 119 | /******/ var ns = Object.create(null); 120 | /******/ __webpack_require__.r(ns); 121 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 122 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 123 | /******/ return ns; 124 | /******/ }; 125 | /******/ 126 | /******/ // getDefaultExport function for compatibility with non-harmony modules 127 | /******/ __webpack_require__.n = function(module) { 128 | /******/ var getter = module && module.__esModule ? 129 | /******/ function getDefault() { return module['default']; } : 130 | /******/ function getModuleExports() { return module; }; 131 | /******/ __webpack_require__.d(getter, 'a', getter); 132 | /******/ return getter; 133 | /******/ }; 134 | /******/ 135 | /******/ // Object.prototype.hasOwnProperty.call 136 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 137 | /******/ 138 | /******/ // __webpack_public_path__ 139 | /******/ __webpack_require__.p = ""; 140 | /******/ 141 | /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; 142 | /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); 143 | /******/ jsonpArray.push = webpackJsonpCallback; 144 | /******/ jsonpArray = jsonpArray.slice(); 145 | /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); 146 | /******/ var parentJsonpFunction = oldJsonpFunction; 147 | /******/ 148 | /******/ 149 | /******/ // run deferred modules from other chunks 150 | /******/ checkDeferredModules(); 151 | /******/ }) 152 | /************************************************************************/ 153 | /******/ ([]); 154 | //# sourceMappingURL=runtime-es2015.js.map -------------------------------------------------------------------------------- /dist/ngx-webworker/bundles/nitinkrmr-ngx-webworker.umd.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : 3 | typeof define === 'function' && define.amd ? define('@nitinkrmr/ngx-webworker', ['exports', '@angular/core'], factory) : 4 | (global = global || self, factory((global.nitinkrmr = global.nitinkrmr || {}, global.nitinkrmr['ngx-webworker'] = {}), global.ng.core)); 5 | }(this, function (exports, core) { 'use strict'; 6 | 7 | /** 8 | * @fileoverview added by tsickle 9 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 10 | */ 11 | var WebworkerService = /** @class */ (function () { 12 | function WebworkerService() { 13 | this.workerFunctionToUrlMap = new WeakMap(); 14 | this.promiseToWorkerMap = new WeakMap(); 15 | } 16 | /** 17 | * @template T 18 | * @param {?} workerFunction 19 | * @param {?=} data 20 | * @return {?} 21 | */ 22 | WebworkerService.prototype.run = /** 23 | * @template T 24 | * @param {?} workerFunction 25 | * @param {?=} data 26 | * @return {?} 27 | */ 28 | function (workerFunction, data) { 29 | /** @type {?} */ 30 | var url = this.getOrCreateWorkerUrl(workerFunction); 31 | return this.runUrl(url, data); 32 | }; 33 | /** 34 | * @param {?} url 35 | * @param {?=} data 36 | * @return {?} 37 | */ 38 | WebworkerService.prototype.runUrl = /** 39 | * @param {?} url 40 | * @param {?=} data 41 | * @return {?} 42 | */ 43 | function (url, data) { 44 | /** @type {?} */ 45 | var worker = new Worker(url); 46 | /** @type {?} */ 47 | var promise = this.createPromiseForWorker(worker, data); 48 | /** @type {?} */ 49 | var promiseCleaner = this.createPromiseCleaner(promise); 50 | this.promiseToWorkerMap.set(promise, worker); 51 | promise.then(promiseCleaner).catch(promiseCleaner); 52 | return promise; 53 | }; 54 | /** 55 | * @template T 56 | * @param {?} promise 57 | * @return {?} 58 | */ 59 | WebworkerService.prototype.terminate = /** 60 | * @template T 61 | * @param {?} promise 62 | * @return {?} 63 | */ 64 | function (promise) { 65 | return this.removePromise(promise); 66 | }; 67 | /** 68 | * @param {?} promise 69 | * @return {?} 70 | */ 71 | WebworkerService.prototype.getWorker = /** 72 | * @param {?} promise 73 | * @return {?} 74 | */ 75 | function (promise) { 76 | return this.promiseToWorkerMap.get(promise); 77 | }; 78 | /** 79 | * @private 80 | * @template T 81 | * @param {?} worker 82 | * @param {?} data 83 | * @return {?} 84 | */ 85 | WebworkerService.prototype.createPromiseForWorker = /** 86 | * @private 87 | * @template T 88 | * @param {?} worker 89 | * @param {?} data 90 | * @return {?} 91 | */ 92 | function (worker, data) { 93 | return new Promise((/** 94 | * @param {?} resolve 95 | * @param {?} reject 96 | * @return {?} 97 | */ 98 | function (resolve, reject) { 99 | worker.addEventListener('message', (/** 100 | * @param {?} event 101 | * @return {?} 102 | */ 103 | function (event) { return resolve(event.data); })); 104 | worker.addEventListener('error', reject); 105 | worker.postMessage(data); 106 | })); 107 | }; 108 | /** 109 | * @private 110 | * @param {?} fn 111 | * @return {?} 112 | */ 113 | WebworkerService.prototype.getOrCreateWorkerUrl = /** 114 | * @private 115 | * @param {?} fn 116 | * @return {?} 117 | */ 118 | function (fn) { 119 | if (!this.workerFunctionToUrlMap.has(fn)) { 120 | /** @type {?} */ 121 | var url = this.createWorkerUrl(fn); 122 | this.workerFunctionToUrlMap.set(fn, url); 123 | return url; 124 | } 125 | return this.workerFunctionToUrlMap.get(fn); 126 | }; 127 | /** 128 | * @private 129 | * @param {?} resolve 130 | * @return {?} 131 | */ 132 | WebworkerService.prototype.createWorkerUrl = /** 133 | * @private 134 | * @param {?} resolve 135 | * @return {?} 136 | */ 137 | function (resolve) { 138 | /** @type {?} */ 139 | var resolveString = resolve.toString(); 140 | /** @type {?} */ 141 | var webWorkerTemplate = "\n self.addEventListener('message', function(e) {\n postMessage((" + resolveString + ")(e.data));\n });\n "; 142 | /** @type {?} */ 143 | var blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 144 | return URL.createObjectURL(blob); 145 | }; 146 | /** 147 | * @private 148 | * @template T 149 | * @param {?} promise 150 | * @return {?} 151 | */ 152 | WebworkerService.prototype.createPromiseCleaner = /** 153 | * @private 154 | * @template T 155 | * @param {?} promise 156 | * @return {?} 157 | */ 158 | function (promise) { 159 | var _this = this; 160 | return (/** 161 | * @param {?} event 162 | * @return {?} 163 | */ 164 | function (event) { 165 | _this.removePromise(promise); 166 | return event; 167 | }); 168 | }; 169 | /** 170 | * @private 171 | * @template T 172 | * @param {?} promise 173 | * @return {?} 174 | */ 175 | WebworkerService.prototype.removePromise = /** 176 | * @private 177 | * @template T 178 | * @param {?} promise 179 | * @return {?} 180 | */ 181 | function (promise) { 182 | /** @type {?} */ 183 | var worker = this.promiseToWorkerMap.get(promise); 184 | if (worker) { 185 | worker.terminate(); 186 | } 187 | this.promiseToWorkerMap.delete(promise); 188 | return promise; 189 | }; 190 | WebworkerService.decorators = [ 191 | { type: core.Injectable } 192 | ]; 193 | return WebworkerService; 194 | }()); 195 | 196 | exports.WebworkerService = WebworkerService; 197 | 198 | Object.defineProperty(exports, '__esModule', { value: true }); 199 | 200 | })); 201 | //# sourceMappingURL=nitinkrmr-ngx-webworker.umd.js.map 202 | -------------------------------------------------------------------------------- /dist/ngx-webworker/esm2015/lib/webworker.service.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | import { Injectable } from '@angular/core'; 6 | export class WebworkerService { 7 | constructor() { 8 | this.workerFunctionToUrlMap = new WeakMap(); 9 | this.promiseToWorkerMap = new WeakMap(); 10 | } 11 | /** 12 | * @template T 13 | * @param {?} workerFunction 14 | * @param {?=} data 15 | * @return {?} 16 | */ 17 | run(workerFunction, data) { 18 | /** @type {?} */ 19 | const url = this.getOrCreateWorkerUrl(workerFunction); 20 | return this.runUrl(url, data); 21 | } 22 | /** 23 | * @param {?} url 24 | * @param {?=} data 25 | * @return {?} 26 | */ 27 | runUrl(url, data) { 28 | /** @type {?} */ 29 | const worker = new Worker(url); 30 | /** @type {?} */ 31 | const promise = this.createPromiseForWorker(worker, data); 32 | /** @type {?} */ 33 | const promiseCleaner = this.createPromiseCleaner(promise); 34 | this.promiseToWorkerMap.set(promise, worker); 35 | promise.then(promiseCleaner).catch(promiseCleaner); 36 | return promise; 37 | } 38 | /** 39 | * @template T 40 | * @param {?} promise 41 | * @return {?} 42 | */ 43 | terminate(promise) { 44 | return this.removePromise(promise); 45 | } 46 | /** 47 | * @param {?} promise 48 | * @return {?} 49 | */ 50 | getWorker(promise) { 51 | return this.promiseToWorkerMap.get(promise); 52 | } 53 | /** 54 | * @private 55 | * @template T 56 | * @param {?} worker 57 | * @param {?} data 58 | * @return {?} 59 | */ 60 | createPromiseForWorker(worker, data) { 61 | return new Promise((/** 62 | * @param {?} resolve 63 | * @param {?} reject 64 | * @return {?} 65 | */ 66 | (resolve, reject) => { 67 | worker.addEventListener('message', (/** 68 | * @param {?} event 69 | * @return {?} 70 | */ 71 | (event) => resolve(event.data))); 72 | worker.addEventListener('error', reject); 73 | worker.postMessage(data); 74 | })); 75 | } 76 | /** 77 | * @private 78 | * @param {?} fn 79 | * @return {?} 80 | */ 81 | getOrCreateWorkerUrl(fn) { 82 | if (!this.workerFunctionToUrlMap.has(fn)) { 83 | /** @type {?} */ 84 | const url = this.createWorkerUrl(fn); 85 | this.workerFunctionToUrlMap.set(fn, url); 86 | return url; 87 | } 88 | return this.workerFunctionToUrlMap.get(fn); 89 | } 90 | /** 91 | * @private 92 | * @param {?} resolve 93 | * @return {?} 94 | */ 95 | createWorkerUrl(resolve) { 96 | /** @type {?} */ 97 | const resolveString = resolve.toString(); 98 | /** @type {?} */ 99 | const webWorkerTemplate = ` 100 | self.addEventListener('message', function(e) { 101 | postMessage((${resolveString})(e.data)); 102 | }); 103 | `; 104 | /** @type {?} */ 105 | const blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 106 | return URL.createObjectURL(blob); 107 | } 108 | /** 109 | * @private 110 | * @template T 111 | * @param {?} promise 112 | * @return {?} 113 | */ 114 | createPromiseCleaner(promise) { 115 | return (/** 116 | * @param {?} event 117 | * @return {?} 118 | */ 119 | (event) => { 120 | this.removePromise(promise); 121 | return event; 122 | }); 123 | } 124 | /** 125 | * @private 126 | * @template T 127 | * @param {?} promise 128 | * @return {?} 129 | */ 130 | removePromise(promise) { 131 | /** @type {?} */ 132 | const worker = this.promiseToWorkerMap.get(promise); 133 | if (worker) { 134 | worker.terminate(); 135 | } 136 | this.promiseToWorkerMap.delete(promise); 137 | return promise; 138 | } 139 | } 140 | WebworkerService.decorators = [ 141 | { type: Injectable } 142 | ]; 143 | if (false) { 144 | /** 145 | * @type {?} 146 | * @private 147 | */ 148 | WebworkerService.prototype.workerFunctionToUrlMap; 149 | /** 150 | * @type {?} 151 | * @private 152 | */ 153 | WebworkerService.prototype.promiseToWorkerMap; 154 | } 155 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2Vid29ya2VyLnNlcnZpY2UuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9Abml0aW5rcm1yL25neC13ZWJ3b3JrZXIvIiwic291cmNlcyI6WyJsaWIvd2Vid29ya2VyLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFLM0MsTUFBTSxPQUFPLGdCQUFnQjtJQUQ3QjtRQUVVLDJCQUFzQixHQUFHLElBQUksT0FBTyxFQUE0QixDQUFDO1FBQ2pFLHVCQUFrQixHQUFHLElBQUksT0FBTyxFQUF3QixDQUFDO0lBc0VuRSxDQUFDOzs7Ozs7O0lBcEVDLEdBQUcsQ0FBSSxjQUFpQyxFQUFFLElB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tcbiAgICByZXR1cm4gKGV2ZW50KSA9PiB7XG4gICAgICB0aGlzLnJlbW92ZVByb21pc2UocHJvbWlzZSk7XG4gICAgICByZXR1cm4gZXZlbnQ7XG4gICAgfTtcbiAgfVxuXG4gIHByaXZhdGUgcmVtb3ZlUHJvbWlzZTxUPihwcm9taXNlOiBQcm9taXNlPFQ+KTogUHJvbWlzZTxUPiB7XG4gICAgY29uc3Qgd29ya2VyID0gdGhpcy5wcm9taXNlVG9Xb3JrZXJNYXAuZ2V0KHByb21pc2UpO1xuICAgIGlmICh3b3JrZXIpIHtcbiAgICAgIHdvcmtlci50ZXJtaW5hdGUoKTtcbiAgICB9XG4gICAgdGhpcy5wcm9taXNlVG9Xb3JrZXJNYXAuZGVsZXRlKHByb21pc2UpO1xuICAgIHJldHVybiBwcm9taXNlO1xuICB9XG59XG4iXX0= -------------------------------------------------------------------------------- /dist/ngx-webworker/esm5/lib/webworker.service.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview added by tsickle 3 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc 4 | */ 5 | import { Injectable } from '@angular/core'; 6 | var WebworkerService = /** @class */ (function () { 7 | function WebworkerService() { 8 | this.workerFunctionToUrlMap = new WeakMap(); 9 | this.promiseToWorkerMap = new WeakMap(); 10 | } 11 | /** 12 | * @template T 13 | * @param {?} workerFunction 14 | * @param {?=} data 15 | * @return {?} 16 | */ 17 | WebworkerService.prototype.run = /** 18 | * @template T 19 | * @param {?} workerFunction 20 | * @param {?=} data 21 | * @return {?} 22 | */ 23 | function (workerFunction, data) { 24 | /** @type {?} */ 25 | var url = this.getOrCreateWorkerUrl(workerFunction); 26 | return this.runUrl(url, data); 27 | }; 28 | /** 29 | * @param {?} url 30 | * @param {?=} data 31 | * @return {?} 32 | */ 33 | WebworkerService.prototype.runUrl = /** 34 | * @param {?} url 35 | * @param {?=} data 36 | * @return {?} 37 | */ 38 | function (url, data) { 39 | /** @type {?} */ 40 | var worker = new Worker(url); 41 | /** @type {?} */ 42 | var promise = this.createPromiseForWorker(worker, data); 43 | /** @type {?} */ 44 | var promiseCleaner = this.createPromiseCleaner(promise); 45 | this.promiseToWorkerMap.set(promise, worker); 46 | promise.then(promiseCleaner).catch(promiseCleaner); 47 | return promise; 48 | }; 49 | /** 50 | * @template T 51 | * @param {?} promise 52 | * @return {?} 53 | */ 54 | WebworkerService.prototype.terminate = /** 55 | * @template T 56 | * @param {?} promise 57 | * @return {?} 58 | */ 59 | function (promise) { 60 | return this.removePromise(promise); 61 | }; 62 | /** 63 | * @param {?} promise 64 | * @return {?} 65 | */ 66 | WebworkerService.prototype.getWorker = /** 67 | * @param {?} promise 68 | * @return {?} 69 | */ 70 | function (promise) { 71 | return this.promiseToWorkerMap.get(promise); 72 | }; 73 | /** 74 | * @private 75 | * @template T 76 | * @param {?} worker 77 | * @param {?} data 78 | * @return {?} 79 | */ 80 | WebworkerService.prototype.createPromiseForWorker = /** 81 | * @private 82 | * @template T 83 | * @param {?} worker 84 | * @param {?} data 85 | * @return {?} 86 | */ 87 | function (worker, data) { 88 | return new Promise((/** 89 | * @param {?} resolve 90 | * @param {?} reject 91 | * @return {?} 92 | */ 93 | function (resolve, reject) { 94 | worker.addEventListener('message', (/** 95 | * @param {?} event 96 | * @return {?} 97 | */ 98 | function (event) { return resolve(event.data); })); 99 | worker.addEventListener('error', reject); 100 | worker.postMessage(data); 101 | })); 102 | }; 103 | /** 104 | * @private 105 | * @param {?} fn 106 | * @return {?} 107 | */ 108 | WebworkerService.prototype.getOrCreateWorkerUrl = /** 109 | * @private 110 | * @param {?} fn 111 | * @return {?} 112 | */ 113 | function (fn) { 114 | if (!this.workerFunctionToUrlMap.has(fn)) { 115 | /** @type {?} */ 116 | var url = this.createWorkerUrl(fn); 117 | this.workerFunctionToUrlMap.set(fn, url); 118 | return url; 119 | } 120 | return this.workerFunctionToUrlMap.get(fn); 121 | }; 122 | /** 123 | * @private 124 | * @param {?} resolve 125 | * @return {?} 126 | */ 127 | WebworkerService.prototype.createWorkerUrl = /** 128 | * @private 129 | * @param {?} resolve 130 | * @return {?} 131 | */ 132 | function (resolve) { 133 | /** @type {?} */ 134 | var resolveString = resolve.toString(); 135 | /** @type {?} */ 136 | var webWorkerTemplate = "\n self.addEventListener('message', function(e) {\n postMessage((" + resolveString + ")(e.data));\n });\n "; 137 | /** @type {?} */ 138 | var blob = new Blob([webWorkerTemplate], { type: 'text/javascript' }); 139 | return URL.createObjectURL(blob); 140 | }; 141 | /** 142 | * @private 143 | * @template T 144 | * @param {?} promise 145 | * @return {?} 146 | */ 147 | WebworkerService.prototype.createPromiseCleaner = /** 148 | * @private 149 | * @template T 150 | * @param {?} promise 151 | * @return {?} 152 | */ 153 | function (promise) { 154 | var _this = this; 155 | return (/** 156 | * @param {?} event 157 | * @return {?} 158 | */ 159 | function (event) { 160 | _this.removePromise(promise); 161 | return event; 162 | }); 163 | }; 164 | /** 165 | * @private 166 | * @template T 167 | * @param {?} promise 168 | * @return {?} 169 | */ 170 | WebworkerService.prototype.removePromise = /** 171 | * @private 172 | * @template T 173 | * @param {?} promise 174 | * @return {?} 175 | */ 176 | function (promise) { 177 | /** @type {?} */ 178 | var worker = this.promiseToWorkerMap.get(promise); 179 | if (worker) { 180 | worker.terminate(); 181 | } 182 | this.promiseToWorkerMap.delete(promise); 183 | return promise; 184 | }; 185 | WebworkerService.decorators = [ 186 | { type: Injectable } 187 | ]; 188 | return WebworkerService; 189 | }()); 190 | export { WebworkerService }; 191 | if (false) { 192 | /** 193 | * @type {?} 194 | * @private 195 | */ 196 | WebworkerService.prototype.workerFunctionToUrlMap; 197 | /** 198 | * @type {?} 199 | * @private 200 | */ 201 | WebworkerService.prototype.promiseToWorkerMap; 202 | } 203 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2Vid29ya2VyLnNlcnZpY2UuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9Abml0aW5rcm1yL25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0cmluZyB7XG4gICAgY29uc3QgcmVzb2x2ZVN0cmluZyA9IHJlc29sdmUudG9TdHJpbmcoKTtcbiAgICBjb25zdCB3ZWJXb3JrZXJUZW1wbGF0ZSA9IGBcbiAgICAgIHNlbGYuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIGZ1bmN0aW9uKGUpIHtcbiAgICAgICAgcG9zdE1lc3NhZ2UoKCR7cmVzb2x2ZVN0cmluZ30pKGUuZGF0YSkpO1xuICAgICAgfSk7XG4gICAgYDtcbiAgICBjb25zdCBibG9iID0gbmV3IEJsb2IoW3dlYldvcmtlclRlbXBsYXRlXSwgeyB0eXBlOiAndGV4dC9qYXZhc2NyaXB0JyB9KTtcbiAgICByZXR1cm4gVVJMLmNyZWF0ZU9iamVjdFVSTChibG9iKTtcbiAgfVxuXG4gIHByaXZhdGUgY3JlYXRlUHJvbWlzZUNsZWFuZXI8VD4ocHJvbWlzZTogUHJvbWlzZTxUPik6IChpbnB1dDogYW55KSA9PiBUIHtcbiAgICByZXR1cm4gKGV2ZW50KSA9PiB7XG4gICAgICB0aGlzLnJlbW92ZVByb21pc2UocHJvbWlzZSk7XG4gICAgICByZXR1cm4gZXZlbnQ7XG4gICAgfTtcbiAgfVxuXG4gIHByaXZhdGUgcmVtb3ZlUHJvbWlzZTxUPihwcm9taXNlOiBQcm9taXNlPFQ+KTogUHJvbWlzZTxUPiB7XG4gICAgY29uc3Qgd29ya2VyID0gdGhpcy5wcm9taXNlVG9Xb3JrZXJNYXAuZ2V0KHByb21pc2UpO1xuICAgIGlmICh3b3JrZXIpIHtcbiAgICAgIHdvcmtlci50ZXJtaW5hdGUoKTtcbiAgICB9XG4gICAgdGhpcy5wcm9taXNlVG9Xb3JrZXJNYXAuZGVsZXRlKHByb21pc2UpO1xuICAgIHJldHVybiBwcm9taXNlO1xuICB9XG59XG4iXX0= -------------------------------------------------------------------------------- /dist/web-wroker-tester/styles-es5.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///./src/styles.css","webpack:////Users/nitin/Sites/projects/angular/libs/ngx-webworker/node_modules/style-loader/lib/addStyles.js","webpack:////Users/nitin/Sites/projects/angular/libs/ngx-webworker/node_modules/style-loader/lib/urls.js","webpack:///./src/styles.css?d690"],"names":[],"mappings":";;;;;;;;;AAAA,mBAAmB,QAAS,iGAAiG,cAAc,eAAe,uCAAuC,GAAG,+CAA+C,6hB;;;;;;;;;;;ACAnP;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,8CAA8C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;;AAEA,cAAc,mBAAO,CAAC,2DAAQ;;AAE9B;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA,iBAAiB,mBAAmB;AACpC;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,iBAAiB,sBAAsB;AACvC;;AAEA;AACA,mBAAmB,2BAA2B;;AAE9C;AACA;AACA;AACA;AACA;;AAEA;AACA,gBAAgB,mBAAmB;AACnC;AACA;;AAEA;AACA;;AAEA,iBAAiB,2BAA2B;AAC5C;AACA;;AAEA,QAAQ,uBAAuB;AAC/B;AACA;AACA,GAAG;AACH;;AAEA,iBAAiB,uBAAuB;AACxC;AACA;;AAEA,2BAA2B;AAC3B;AACA;AACA;;AAEA;AACA;AACA;;AAEA,gBAAgB,iBAAiB;AACjC;AACA;AACA;AACA;AACA;AACA,cAAc;;AAEd,kDAAkD,sBAAsB;AACxE;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,GAAG;AACH;AACA,GAAG;AACH;AACA;AACA;AACA,EAAE;AACF;AACA,EAAE;AACF;AACA;AACA,EAAE;AACF;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,EAAE;AACF;;AAEA;AACA,KAAK,KAAwC,EAAE,EAE7C;;AAEF,QAAQ,sBAAiB;AACzB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,CAAC;;AAED;AACA;;AAEA;AACA;AACA,EAAE;AACF;AACA;;AAEA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,EAAE;AACF;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uDAAuD;AACvD;;AAEA,6BAA6B,mBAAmB;;AAEhD;;AAEA;;AAEA;AACA;;;;;;;;;;;;;AC9YA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,wCAAwC,WAAW,EAAE;AACrD,wCAAwC,WAAW,EAAE;;AAErD;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,GAAG;AACH;AACA,sCAAsC;AACtC,GAAG;AACH;AACA,8DAA8D;AAC9D;;AAEA;AACA;AACA,EAAE;;AAEF;AACA;AACA;;;;;;;;;;;;;ACvFA,cAAc,mBAAO,CAAC,+UAAgL;;AAEtM,4CAA4C,QAAS;;AAErD;AACA;;;;AAIA,eAAe;;AAEf;AACA;;AAEA,aAAa,mBAAO,CAAC,6GAAsD;;AAE3E;;AAEA,GAAG,KAAU,EAAE,E","file":"styles-es5.js","sourcesContent":["module.exports = [[module.id, \"/* You can add global styles to this file, and also import other style files */\\nhtml,\\nbody {\\n margin: 0;\\n padding: 0;\\n font-family: 'PT Sans', sans-serif;\\n}\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByb2plY3RzL3dlYi13cm9rZXItdGVzdGVyL3NyYy9zdHlsZXMuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDhFQUE4RTtBQUM5RTs7RUFFRSxTQUFTO0VBQ1QsVUFBVTtFQUNWLGtDQUFrQztBQUNwQyIsImZpbGUiOiJwcm9qZWN0cy93ZWItd3Jva2VyLXRlc3Rlci9zcmMvc3R5bGVzLmNzcyIsInNvdXJjZXNDb250ZW50IjpbIi8qIFlvdSBjYW4gYWRkIGdsb2JhbCBzdHlsZXMgdG8gdGhpcyBmaWxlLCBhbmQgYWxzbyBpbXBvcnQgb3RoZXIgc3R5bGUgZmlsZXMgKi9cbmh0bWwsXG5ib2R5IHtcbiAgbWFyZ2luOiAwO1xuICBwYWRkaW5nOiAwO1xuICBmb250LWZhbWlseTogJ1BUIFNhbnMnLCBzYW5zLXNlcmlmO1xufVxuIl19 */\", '', '']]","/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra\n*/\n\nvar stylesInDom = {};\n\nvar\tmemoize = function (fn) {\n\tvar memo;\n\n\treturn function () {\n\t\tif (typeof memo === \"undefined\") memo = fn.apply(this, arguments);\n\t\treturn memo;\n\t};\n};\n\nvar isOldIE = memoize(function () {\n\t// Test for IE <= 9 as proposed by Browserhacks\n\t// @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805\n\t// Tests for existence of standard globals is to allow style-loader\n\t// to operate correctly into non-standard environments\n\t// @see https://github.com/webpack-contrib/style-loader/issues/177\n\treturn window && document && document.all && !window.atob;\n});\n\nvar getTarget = function (target, parent) {\n if (parent){\n return parent.querySelector(target);\n }\n return document.querySelector(target);\n};\n\nvar getElement = (function (fn) {\n\tvar memo = {};\n\n\treturn function(target, parent) {\n // If passing function in options, then use it for resolve \"head\" element.\n // Useful for Shadow Root style i.e\n // {\n // insertInto: function () { return document.querySelector(\"#foo\").shadowRoot }\n // }\n if (typeof target === 'function') {\n return target();\n }\n if (typeof memo[target] === \"undefined\") {\n\t\t\tvar styleTarget = getTarget.call(this, target, parent);\n\t\t\t// Special case to return head of iframe instead of iframe itself\n\t\t\tif (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {\n\t\t\t\ttry {\n\t\t\t\t\t// This will throw an exception if access to iframe is blocked\n\t\t\t\t\t// due to cross-origin restrictions\n\t\t\t\t\tstyleTarget = styleTarget.contentDocument.head;\n\t\t\t\t} catch(e) {\n\t\t\t\t\tstyleTarget = null;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmemo[target] = styleTarget;\n\t\t}\n\t\treturn memo[target]\n\t};\n})();\n\nvar singleton = null;\nvar\tsingletonCounter = 0;\nvar\tstylesInsertedAtTop = [];\n\nvar\tfixUrls = require(\"./urls\");\n\nmodule.exports = function(list, options) {\n\tif (typeof DEBUG !== \"undefined\" && DEBUG) {\n\t\tif (typeof document !== \"object\") throw new Error(\"The style-loader cannot be used in a non-browser environment\");\n\t}\n\n\toptions = options || {};\n\n\toptions.attrs = typeof options.attrs === \"object\" ? options.attrs : {};\n\n\t// Force single-tag solution on IE6-9, which has a hard limit on the # of