11# Workerpool
22
3- An unopinionated small scale worker pool abstraction which serves as a base interface for more advanced worker managers.
3+ An unopinionated small scale worker pool abstraction which serves as a base
4+ interface for more advanced worker managers.
45
56## Terminology
67
781 . ** Workerpool**
89
9- A manager that creates workers on the fly, executing tasks up to defined concurrency.
10+ A manager that creates workers on the fly, executing tasks up to defined
11+ concurrency.
1012
11132 . ** Runner**
1214
13- Runners are internal wrappers for user provided runner classes, they maintain internal states such as active/busy and the retry counter.
15+ Runners are internal wrappers for user provided runner classes, they maintain
16+ internal states such as active/busy and the retry counter.
1417
15183 . ** Executable**
1619
17- User implementation of task executors, where they all implements the ` Executable ` interface.
20+ User implementation of task executors, where they all implements the
21+ ` Executable ` interface.
1822
19- Also called _ workers_ for the sake of naming convension, but the usage kept minimal to avoid confusion with Web Workers.
23+ Also called _ workers_ for the sake of naming convension, but the usage kept
24+ minimal to avoid confusion with Web Workers.
2025
21264 . ** Task**
2227
@@ -94,15 +99,26 @@ const pool = new Workerpool<Payload>({
9499
95100### Web Workers
96101
97- Deno has built-in support for workers, our ` ExecutableWorker ` class serves as a simple proxy class via ` comlink ` .
102+ Deno has built-in support for workers, our ` ExecutableWorker ` class serves as a
103+ simple proxy class via ` comlink ` .
98104
99- You'll need a separated script file for the worker.
105+ ``` ts
106+ import { ExecutableWorker } from " https://deno.land/x/workerpool/mod.ts" ;
107+
108+ class MyRunner extends ExecutableWorker <string , void > {
109+ constructor () {
110+ super (new URL (" ./worker.ts" , import .meta .url ).href );
111+ }
112+ }
113+ ```
114+
115+ You'll also need a separated script file for the worker itself.
100116
101117``` ts
102118// worker.ts
103- import { expose } from " https://deno.land/x/comlink /mod.ts" ;
119+ import { initializeWorker } from " https://deno.land/x/workerpool /mod.ts" ;
104120
105- expose ({
121+ initializeWorker ({
106122 execute : async (payload : string ) => {
107123 // Simulate async actions
108124 await new Promise ((resolve ) => setTimeout (resolve , 1000 ));
@@ -112,18 +128,10 @@ expose({
112128});
113129```
114130
115- Now register the runners into the workerpool:
131+ Now register the runner into the workerpool:
116132
117133``` ts
118- import { ExecutableWorker } from " https://deno.land/x/workerpool/mod.ts" ;
119-
120- class MyRunner extends ExecutableWorker <string , void > {
121- constructor () {
122- super (new URL (" ./worker.ts" , import .meta .url ).href );
123- }
124- }
125-
126- const pool = new Workerpool ({
134+ const pool = new Workerpool <string , void >({
127135 concurrency: 1 ,
128136 workers: [MyRunner ],
129137});
136144
137145## Sponsorship
138146
139- If you appreciate my work, or want to see specific features to happen, [ a coffee would do] ( https://www.github.com/sponsors/vicary ) .
147+ If you appreciate my work, or want to see specific features to happen,
148+ [ a coffee would do] ( https://www.github.com/sponsors/vicary ) .
0 commit comments