Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ And with `multee`, it's just as easy as calling an async function.
```javascript
// worker.js
const Multee = require('multee')
const multee = Multee('worker') // worker_threads, use 'child' for child_process
const multee = Multee('worker') // 'worker' for worker_threads | 'child' for child_process

export const jobA = multee.createHandler('jobA', () => {
const jobA = multee.createHandler('jobA', () => {
// do the heavy load here
let result = 0
for (let i = 0; i < 100; i++) {
Expand All @@ -54,18 +54,25 @@ export const jobA = multee.createHandler('jobA', () => {
return result
})

module.exports = () => {
const worker = multee.start(__filename)
return { result: jobA(worker) }
module.exports = {
start: () => {
const worker = multee.start(__filename)
return {
test: jobA(worker),
worker: worker
}
}
}

// master.js
async function partA() {
const worker = require('./worker')
const result = await worker.jobA()
const test = worker.start()
const result = await test.test()
// do the rest with result
console.log(result)
// { result: 4950 }
test.worker.terminate()
}
```

Expand Down