diff --git a/package.json b/package.json index 7f30fd2..ec5a1bb 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,15 @@ "name": "worka", "version": "1.0.0", "description": "", - "main": "source/worka.js", - "module": "module", + "main": "built/worka_script.js", + "module": "source/worka.js", "directories": { "example": "example" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "rollup": "rollup example/estimatePi.js --format cjs --output example/estimatePiNode.js" + "buildExample": "rollup example/estimatePi.js --format cjs --output example/estimatePiNode.js", + "buildBrowser": "rollup source/worka.js --format iife --output built/worka_script.js" }, "author": "", "license": "ISC" diff --git a/readme.md b/readme.md index e907908..2eecfe2 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ ## Why -Make lifer easier. Working with Web Workers is cool, I can do all sorts, it makes things previously only available to native apps possible on the web also. Multi threading is hard to get right, and that's why I use patterns to stay correct. Many patterns are duplicated across different applications. Avoiding duplication is a good thing, I was told. +Make lifer easier. Working with Web Workers is cool, it makes things previously only available to native apps possible on the web also. Multi threading is hard to get right, and that's why I use patterns to stay correct. Many patterns are duplicated across different applications. These patterns are now internalized into a library to avoiding duplication. ## What @@ -14,6 +14,7 @@ Abstraction layer on top of web worker, with declarative life cycle. Encapsulati * Worker auto split into more worker * Time out management * Opt in statefull worker + * Lifecycle management ## How @@ -21,12 +22,45 @@ Abstraction layer on top of web worker, with declarative life cycle. Encapsulati With a script to be imported. [worka.js](./source/worka.js) -### Short Example +## Inspiration + +Inspired by the clean stateless HTTP architecture, something comes in, something comes out. Below is an example where you can even race with the network. + + +### Short Example (source/worka.html) ``` -import { registerWorker, SYMBOLS, work } from "../source/worka.js"; -TODO + + + + + + + +

Open console

+ + + + ``` @@ -35,7 +69,7 @@ TODO Inside web worker: https://nolanlawson.github.io/html5workertest/ . -The functions must be synchronous. +The functions must be synchronous. Only available as ES module for now. Requires full ES2015 and more support. Requires ES Promises. Does not support @@ -44,7 +78,7 @@ Does not support ## Install -Download `work.js` +Download `source/worka.js` @@ -52,14 +86,15 @@ Download `work.js` * [work](#work) * [registerWorker](#registerWorker) - * [SYMBOLS](#SYMBOLS) + * [SYMBOLS](#symbols) + ### work `work(name, input);` -Returns a promise that eventually resolves with the result or fails. +Returns a promise that eventually resolves with the result or fails. Use registerWorker first ! ``` @@ -89,7 +124,7 @@ the name of the worker or `${name}/${functionName}`. The input that will be provided to the worker. To pass multiple inputs use a container, such as an Array or an Object. -### .registerWorker +### registerWorker `registerWorker(options);` @@ -463,7 +498,7 @@ Memoize is not included by default for maximum flexibility. It is possible to me ``` // imports const promiseMemoize = require("promise-memoize"); -const { registerWorker, work, SYMBOLS} = require("work"); +const { registerWorker, work, SYMBOLS} = require("worka"); // require not supported yet // register worker @@ -492,9 +527,19 @@ const memoizedWork = promiseMemoize(work); ## Alternatives * https://github.com/andywer/threads.js + * Also works for NodeJS + * Also for non ES6 + * Transferrables + * More complex * https://github.com/padolsey/operative + * Falls back to using iframes + * high range of browser support + * Promise or callback based * https://github.com/nolanlawson/promise-worker + * Small + * Also promised based * raw web worker + * More freedom but might have to reinvent patterns discovered here diff --git a/source/work.html b/source/work.html deleted file mode 100644 index ea513ec..0000000 --- a/source/work.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - HTML TEMPLATE - - - - -

open console

- - - - diff --git a/source/worka.html b/source/worka.html new file mode 100644 index 0000000..28117bf --- /dev/null +++ b/source/worka.html @@ -0,0 +1,29 @@ + + + + + + + +

Open console

+ + +