@@ -24,6 +24,9 @@ An unopinionated small scale worker pool abstraction which serves as a base inte
2424
2525## Basic Usage
2626
27+ You need to implement your own ` enqueue ` and ` dequeue ` logic, see an in-memory
28+ implementation in the examples section.
29+
2730``` ts
2831import { Executable , Workerpool } from " https://deno.land/x/workerpool/mod.ts" ;
2932
@@ -33,6 +36,8 @@ class RunnerB implements Executable {...}
3336const pool = new Workerpool ({
3437 concurrency: 2 ,
3538 workers: [RunnerA , RunnerB ]
39+ // enqueue() {...}
40+ // dequeue() {...}
3641});
3742
3843pool
4146 .start ();
4247```
4348
44- ## Runner Examples
49+ ## Examples
4550
4651### In-memory Queue
4752
48- As a proof of concept, this is the most basic implementation of an in-memory queue.
53+ As a proof of concept, this is a simple implementation of an in-memory queue.
4954
5055``` ts
5156type Payload = any ;
@@ -54,23 +59,23 @@ type MemoryMutexTask = Task<Payload> & { active?: boolean };
5459const tasks = new Set <MemoryMutexTask >();
5560const pool = new Workerpool <Payload >({
5661 concurrency: 1 ,
57- runners : [runnerA , runnerB ],
62+ workers : [RunnerA , RunnerB ],
5863 enqueue(task : MemoryMutexTask ) {
5964 task .active = false ;
6065 tasks .add (task );
6166 },
6267 dequeue() {
6368 // Uncomment the following line for FIFO queues
64- // if ([...tasks].some(( { active }) => active) ) return;
69+ // for (const { active } of task) if ( active) return;
6570
6671 for (const task of tasks ) {
6772 if (! task .active ) {
68- task .busy = true ;
73+ task .active = true ;
6974 return task ;
7075 }
7176 }
7277 },
73- onTaskFinish (error , result , { task }) {
78+ onTaskFinished (error , result , { task }) {
7479 tasks .delete (task );
7580
7681 if (error ) {
0 commit comments