{"id":26243576,"url":"https://github.com/morrisjdev/ng-webworker-helper","last_synced_at":"2025-03-13T10:28:44.537Z","repository":{"id":54552646,"uuid":"154486469","full_name":"morrisjdev/ng-webworker-helper","owner":"morrisjdev","description":"a helper to use webworker in an angular application","archived":false,"fork":false,"pushed_at":"2022-10-05T17:51:18.000Z","size":718,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T13:18:51.578Z","etag":null,"topics":["angular","ng-webworker-helper","typescript","web-worker","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morrisjdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-24T11:03:25.000Z","updated_at":"2019-01-05T20:08:13.000Z","dependencies_parsed_at":"2022-08-13T19:30:42.069Z","dependency_job_id":null,"html_url":"https://github.com/morrisjdev/ng-webworker-helper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrisjdev%2Fng-webworker-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrisjdev%2Fng-webworker-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrisjdev%2Fng-webworker-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrisjdev%2Fng-webworker-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morrisjdev","download_url":"https://codeload.github.com/morrisjdev/ng-webworker-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243385381,"owners_count":20282566,"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","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":["angular","ng-webworker-helper","typescript","web-worker","workers"],"created_at":"2025-03-13T10:28:43.926Z","updated_at":"2025-03-13T10:28:44.526Z","avatar_url":"https://github.com/morrisjdev.png","language":"JavaScript","readme":"# ng-webworker-helper [![Build Status](https://travis-ci.org/morrisjdev/ng-webworker-helper.svg?branch=master)](https://travis-ci.org/morrisjdev/ng-webworker-helper) [![Maintainability](https://api.codeclimate.com/v1/badges/1c7beb2c8cb98f25a166/maintainability)](https://codeclimate.com/github/morrisjdev/ng-webworker-helper/maintainability)\n\nThis project is an extension for Angular that should make working with WebWorker simple. This project enables you to\nrun code in a seperate thread and make the UI run faster.\n\n## Installation\n\nTo use the project use\n\n```\nnpm install ng-webworker-helper -S\nnpm install concurrently -D\n```\n\n\n### Building the webworker files\n\nYou can now use Webworkers, but you have to enable Angular to transpile your webworker files into a seperate .js file.\n\nFirst of all copy the files [webworker.webpack.config.js](webworker.webpack.config.js) and \n[webworker.webpack.dev.config.js](webworker.webpack.dev.config.js) in your projects root folder.\nThen copy the file [src/tsconfig.worker.json](src/tsconfig.worker.json) to your src folder.\n\nNow add this entries to the `angular.json` of your project:\n\n```json\n{\n ...,\n \"architect\": {\n    ...,\n    \"build-worker\": {\n      \"builder\": \"@angular-devkit/build-webpack:webpack\",\n      \"options\": {\n        \"webpackConfig\": \"./webworker.webpack.config.js\"\n      }\n    },\n    \"dev-worker\": {\n      \"builder\": \"@angular-devkit/build-webpack:webpack\",\n      \"options\": {\n        \"webpackConfig\": \"./webworker.webpack.dev.config.js\"\n      }\n    },\n    ...\n  }\n}\n```\n\nIn your `package.json` add the entries\n```\n\"build-worker\": \"ng run \u003cprojectname\u003e:build-worker\",\n\"dev-worker\": \"ng run \u003cprojectname\u003e:dev-worker\"\n```\nto the scripts section.\n\nChange the scripts `build`  and `start` like this:\n```\n\"start\": \"concurrently --kill-others \\\"npm run dev-worker\\\" \\\"ng serve\\\"\",\n\"build\": \"npm run build-worker \u0026\u0026 ng build\",\n```\n\n### Add provider in angular\n\nIn your `app.module.ts` add `NgWebworkerService` in the providers section.\n\n\n## Usage\n\nTo use webworkers you have to create the folder `worker` in the src directory of your project.\nCreate a file named `main.worker.ts` with the following content:\n\n````js\nimport {registerWebworker, WebworkerHandlerBase} from 'ng-webworker-helper';\n\nregisterWebworker({\n  'test': TestWorker\n});\n````\n\nNow you can create files with custom worker code for example `test.worker.ts`:\n````\nclass TestWorker extends WebworkerHandlerBase {\n  run(data: number): number {\n    const before = new Date();\n    let count = 0;\n\n    this.send('das ist ein test');\n\n    while (true) {\n      count++;\n      const now = new Date();\n      if (now.valueOf() - before.valueOf() \u003e data) {\n        break;\n      }\n    }\n\n    return count;\n  }\n}\n````\n\nYou can execute the function in a worker using:\n\n````\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.less']\n})\nexport class AppComponent {\n  constructor(private webworkerService: NgWebworkerService) {\n  \n    //This executes code in TestWorker \n    this.webworkerService.execute('test', 10000).subscribe(console.log);\n\n    //This executes a custom function in a webworker thread\n    this.webworkerService.executeFunction((t) =\u003e {\n      return t * 10;\n    }, 100).subscribe(console.log);\n\n  }\n}\n````\n\n## Author\n\n[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorrisjdev%2Fng-webworker-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorrisjdev%2Fng-webworker-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorrisjdev%2Fng-webworker-helper/lists"}