{"id":15497209,"url":"https://github.com/jwerle/woop","last_synced_at":"2025-07-07T06:33:01.166Z","repository":{"id":24995992,"uuid":"28414837","full_name":"jwerle/woop","owner":"jwerle","description":"WebWorker event loop","archived":false,"fork":false,"pushed_at":"2014-12-23T19:37:35.000Z","size":117,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T03:17:54.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jwerle.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":"2014-12-23T19:10:18.000Z","updated_at":"2014-12-23T19:51:54.000Z","dependencies_parsed_at":"2022-08-17T15:45:37.831Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/woop","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jwerle/woop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fwoop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fwoop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fwoop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fwoop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/woop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fwoop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264027564,"owners_count":23546099,"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":[],"created_at":"2024-10-02T08:31:51.708Z","updated_at":"2025-07-07T06:33:01.123Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"woop\n====\n\nWebWorker event loop. Queue functions to be executed in web workers in\nan event loop context. Work can last forever or be completed later.\nFunctions can have bound arguments when pushed to the loop queue which\nwill be exposed to the function executed in a webworker.\n\n## install\n\nWith [component](https://github.com/componentjs/component):\n\n```sh\n$ component install jwerle/woop\n```\n\nFrom source:\n\n```sh\n$ wget https://raw.githubusercontent.com/qute/qute/master/woop.js\n```\n\n## usage\n\nWith [component](https://github.com/componentjs/component):\n\n```js\nvar loop = require('woop').createLoop();\n```\n\nGlobal scope:\n\n```js\nvar loop = woop.createLoop();\n```\n\n## example\n\nThis example demonstrates a simple echo worker. It accepts a single\nargument and replies with that same argument.\n\n```js\nvar loop = woop.createLoop();\n\nloop\n.push(function (data, done) {\n    done(true, data.arguments[0]);\n}, 'echo')\n.on('done', function (e) {\n    console.log(e.message); // 'echo'\n})\n.dequeue();\n```\n\n## api\n\n### createLoop\n\nThis returns an instance of `Loop` where \"work\" can be pushed and then\ndequeued.\n\n```js\nvar loop = woop.createLoop();\n```\n\n### Loop()\n\nThe `Loop` constructor.\n\n```js\nvar loop = new woop.Loop();\n```\n\n#### Loop#push(work, [...arguments])\n\nPush work onto the loop queue to be dequeued later with optional bound\narguments.\n\n```js\nloop.push(work, \"beep\", \"boop\");\nfunction work (data, done) {\n  console.log(data.arguments); // [\"beep\", \"boop\"]\n  done(true, 'beeboop');\n});\n```\n\nA worker function accepts two arguments. The `data` argument which is an\nobject that contains an `arguments` property. The `arguments` property\nis an array of optional arguments passed with the function when queued.\nThe second argument `done` is a callback function. When you call this\nfunction it emits a response to the main thread with optional data. The\n`done` function accepts two arguments. The first argument is a `boolean`\nsignaling whether work in the wokrer is complete. If `done(true)` is\npassed the worker will terminate. Any javascript after the call to `done(true)`\nwill cause undefined behavior. If you want your worker to stay alive\nthen call `done(false)`. Calling `done(true)` will cause a 'done'\nevent to be emitted on the main thread. All calls to `done(false)` will\nemit a 'message' event.\n\n#### Loop#dequeue([done])\n\nThis will cause the event queue to dequeue itself. This will occur\nasynchronously. When the loop has successfully dequeued it will call an\noptional `done` callback if provided.\n\n```js\nloop.dequeue(function () {\n  console.log(\"loop dequeued\");\n});\n```\n\n### events\n\nDuring a dequeue process some events are emitted to give insight into\nwhat is going on with the workers.\n\n#### 'done'\n\nThis event is emitted when a worker has completed. The underlying\n`WebWorker` will be terminated (`worker.terminate()`) by the time this\nevent is emitted.\n\n\n```js\nloop.on('done', function (e) {\n  console.log(e.message);\n});\n```\n\n#### message\n\nThis event is emitted when a worker emits a response. This event is\nemitted in conjunction with the 'done' event if a webworker has\ncompleted.\n\n```js\nloop.on('message', function (e) {\n  console.log(e.message);\n});\n```\n\n## license\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fwoop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fwoop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fwoop/lists"}