Skip to content

Commit

Permalink
docs(README.md): revert reformatting
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Oct 14, 2024
1 parent cd7406c commit 5561f4e
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5561f4e

Please sign in to comment.