{"id":20190081,"url":"https://github.com/start-javascript/ngx-web-worker","last_synced_at":"2025-10-07T23:12:24.568Z","repository":{"id":45827696,"uuid":"118026192","full_name":"start-javascript/ngx-web-worker","owner":"start-javascript","description":"Web worker for angular.","archived":false,"fork":false,"pushed_at":"2019-07-11T03:27:26.000Z","size":2567,"stargazers_count":33,"open_issues_count":13,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-18T22:34:15.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/start-javascript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-18T19:12:09.000Z","updated_at":"2024-07-14T06:33:24.000Z","dependencies_parsed_at":"2022-08-01T01:08:01.190Z","dependency_job_id":null,"html_url":"https://github.com/start-javascript/ngx-web-worker","commit_stats":null,"previous_names":["nitinkrmr/ngx-web-worker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/start-javascript/ngx-web-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/start-javascript%2Fngx-web-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/start-javascript%2Fngx-web-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/start-javascript%2Fngx-web-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/start-javascript%2Fngx-web-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/start-javascript","download_url":"https://codeload.github.com/start-javascript/ngx-web-worker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/start-javascript%2Fngx-web-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278861029,"owners_count":26058632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T03:40:29.791Z","updated_at":"2025-10-07T23:12:24.522Z","avatar_url":"https://github.com/start-javascript.png","language":"TypeScript","readme":"# What is this?\n\n[Web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers)\nservice for [Angular](https://angular.io).\n\n## [Demo](https://start-javascript.github.io/ngx-web-worker/)\n\n# Install\n\n```shell\nnpm i ngx-web-worker\n```\n\n# API\n\n```javascript\nexport interface IWebWorkerService {\n  run\u003cT\u003e(workerFunction: (any) =\u003e T, data?: any): Promise\u003cT\u003e;\n  runUrl(url: string, data?: any): Promise\u003cany\u003e;\n  terminate\u003cT\u003e(promise: Promise\u003cT\u003e): Promise\u003cT\u003e;\n}\n```\n\n- `run`\n\n  - `workerFunction`:\n\n    - Must be a self-contained function. Cannot reference outside variables.\n    - You can import other libraries with\n      [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts)\n      though\n    - These are okay:\n    - ```javascript\n      run(input =\u003e input * input, 10);\n\n      run(input =\u003e {\n          const square = num =\u003e num * num;\n          return square(input);\n      }, 10);\n\n      const someFunction = (input) =\u003e input * input);\n      run(someFunction, 10);\n\n      class Runner {\n          private webWorkerService = new WebWorkerService();\n          constructor() {\n              this.webWorkerService.run(this.someFunction, 10);\n          }\n          someFunction() {\n              return input * input;\n          }\n      }\n      ```\n\n    - These will probably **NOT** work:\n    - ```javascript\n      // this is not okay because inside the context of the web worker `this` is not the same `this` as here.\n      run(input =\u003e this.square(input), 10);\n\n      // this is not okay because `_` doesn't exist in the web worker context (assuming tht `_` is available here to begin with)\n      run(input =\u003e {\n        return _.uniqueId() * input;\n      }, 10);\n      ```\n\n  - `data`:\n    [serializable data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)\n\n- `runUrl`: Basically the same as\n  - `url`: The url you would use to create a\n    [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) instance\n  - `data`: Same as the `run` method\n- `terminate`: Calling this will\n  [`terminate`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) the web worker,\n  if it is still running.\n  - `promise`: The `Promise` instance returned by `run` or `runUrl`.\n\n# Example\n\nCheck out [ngx-web-worker-example](https://github.com/nitinkrmr/ngx-web-worker-example) for a\nsample project, or see [`app/app.component.ts`](app/app.component.ts) for usage with an Angular\napplication.\n\n```\nexport class AppComponent implements OnInit {\n    constructor(private _webWorkerService: WebWorkerService) {\n    }\n\n    ngOnInit() {\n        const input = 100;\n        const promise = this._webWorkerService.run(this.someCPUHeavyFunction, input);\n        promise.then(result =\u003e console.log(result));\n    }\n\n    someCPUHeavyFunction (input) {\n        return input * 10;\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstart-javascript%2Fngx-web-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstart-javascript%2Fngx-web-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstart-javascript%2Fngx-web-worker/lists"}