-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(README.md): revert reformatting
Signed-off-by: Jérôme Benoit <[email protected]>
- Loading branch information
1 parent
cd7406c
commit 5561f4e
Showing
1 changed file
with
45 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ for more details**: | |
<!-- deno-fmt-ignore --> | ||
|
||
```js | ||
<script type="module">import {ThreadWorker} from 'https://cdn.jsdelivr.net/npm/[email protected]/browser/mod.js'</script> | ||
<script type="module">import { ThreadWorker } from 'https://cdn.jsdelivr.net/npm/[email protected]/browser/mod.js'</script> | ||
``` | ||
|
||
```js | ||
|
@@ -189,28 +189,57 @@ Instantiate your pool based on your needs : | |
|
||
```js | ||
// adapt import to the targeted JS runtime | ||
import { availableParallelism, DynamicThreadPool, FixedThreadPool, PoolEvents } from '@poolifier/poolifier-web-worker' | ||
import { | ||
availableParallelism, | ||
DynamicThreadPool, | ||
FixedThreadPool, | ||
PoolEvents, | ||
} from '@poolifier/poolifier-web-worker' | ||
|
||
// a fixed web worker pool | ||
const pool = new FixedThreadPool(availableParallelism(), new URL('./yourWorker.js', import.meta.url), { | ||
errorEventHandler: e => { | ||
console.error(e) | ||
const pool = new FixedThreadPool( | ||
availableParallelism(), | ||
new URL('./yourWorker.js', import.meta.url), | ||
{ | ||
errorEventHandler: (e) => { | ||
console.error(e) | ||
}, | ||
}, | ||
}) | ||
) | ||
|
||
pool.eventTarget?.addEventListener(PoolEvents.ready, () => console.info('Pool is ready')) | ||
pool.eventTarget?.addEventListener(PoolEvents.busy, () => console.info('Pool is busy')) | ||
pool.eventTarget?.addEventListener( | ||
PoolEvents.ready, | ||
() => console.info('Pool is ready'), | ||
) | ||
pool.eventTarget?.addEventListener( | ||
PoolEvents.busy, | ||
() => console.info('Pool is busy'), | ||
) | ||
|
||
// or a dynamic web worker pool | ||
const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), new URL('./yourWorker.js', import.meta.url), { | ||
errorEventHandler: e => { | ||
console.error(e) | ||
const pool = new DynamicThreadPool( | ||
Math.floor(availableParallelism() / 2), | ||
availableParallelism(), | ||
new URL('./yourWorker.js', import.meta.url), | ||
{ | ||
errorEventHandler: (e) => { | ||
console.error(e) | ||
}, | ||
}, | ||
}) | ||
|
||
pool.eventTarget?.addEventListener(PoolEvents.full, () => console.info('Pool is full')) | ||
pool.eventTarget?.addEventListener(PoolEvents.ready, () => console.info('Pool is ready')) | ||
pool.eventTarget?.addEventListener(PoolEvents.busy, () => console.info('Pool is busy')) | ||
) | ||
|
||
pool.eventTarget?.addEventListener( | ||
PoolEvents.full, | ||
() => console.info('Pool is full'), | ||
) | ||
pool.eventTarget?.addEventListener( | ||
PoolEvents.ready, | ||
() => console.info('Pool is ready'), | ||
) | ||
pool.eventTarget?.addEventListener( | ||
PoolEvents.busy, | ||
() => console.info('Pool is busy'), | ||
) | ||
|
||
// the execute method signature is the same for both implementations, | ||
// so you can easily switch from one to another | ||
|