easy-web-worker 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,17 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
Hello and Welcome to **easy-web-worker** with [cancelable-promise-jq](https://www.npmjs.com/package/cancelable-promise-jq) - Your new go-to solution for seamless web worker integration enhanced with **cancelable promises** in JavaScript! 🚀
|
|
5
|
+
Hello and Welcome to **easy-web-worker** with [cancelable-promise-jq](https://www.npmjs.com/package/cancelable-promise-jq) - Your new go-to solution for seamless web worker integration enhanced with **cancelable promises** in JavaScript! 🚀 Check out the running example on [CODEPEN](https://codepen.io/johnnynabetes/pen/wvOvygW?editors=0010)
|
|
6
6
|
|
|
7
|
-
Are you tired of the hassle involved in setting up and managing web workers? Look no further! And take a look
|
|
7
|
+
Are you tired of the hassle involved in setting up and managing web workers? Look no further! And take a look!
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
+
/**
|
|
11
|
+
* Creating a web worker never was easier:
|
|
12
|
+
*
|
|
13
|
+
* The callback parameter will be the body of the worker
|
|
14
|
+
*/
|
|
10
15
|
const worker = new EasyWebWorker((easyWorker) => {
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Inside the worker we have to define an action when onMessage
|
|
18
|
+
*/
|
|
12
19
|
easyWorker.onMessage((message) => {
|
|
13
|
-
const { payload } = message;
|
|
14
|
-
|
|
15
|
-
console.log(payload); // Hello Worker!
|
|
20
|
+
const { payload } = message; // The payload includes whatever parameters are sent from the main thread
|
|
16
21
|
|
|
17
22
|
// do something heavy...
|
|
18
23
|
|
|
@@ -22,11 +27,16 @@ const worker = new EasyWebWorker((easyWorker) => {
|
|
|
22
27
|
//message.reject(); // or reject
|
|
23
28
|
});
|
|
24
29
|
});
|
|
30
|
+
```
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
Then, for sending a message to the worker:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
27
35
|
await worker.send('Hello Worker!');
|
|
28
36
|
```
|
|
29
37
|
|
|
38
|
+
And that's it! You now have a worker running heavy computation in a real separate thread, with real asynchronous programming in JavaScript.
|
|
39
|
+
|
|
30
40
|
**easy-web-worker** is designed to enhance the capabilities of the **Worker** class by integrating a pattern of cancelable promises from the **[cancelable-promise-jq](https://www.npmjs.com/package/cancelable-promise-jq)** library. For straightforward tasks, it simplifies the process by eliminating the need to configure webpack or other bundlers. And for more complex requirements, the **StaticEasyWebWorker** class allows the integration of easy worker and cancelable promises capabilities into your static workers.
|
|
31
41
|
|
|
32
42
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-web-worker",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "This is a library to easily handle and create web-workers, if you are a web developer and never tried this... do not wait any longer! Workers are an amazing option to improve user experience and make your webpages even greater",
|
|
5
5
|
"main": "lib/bundle.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|