From 2d54c32e2fa51f6b88ad870365db9844ebf984c7 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Sun, 16 Jan 2022 17:41:26 +0200 Subject: [PATCH 1/4] Fix documentation usability in README. --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1dc25ff..862d500 100644 --- a/README.md +++ b/README.md @@ -43,29 +43,33 @@ 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++) { - result += heavy_and_return_same(i) + console.log('jobA') + return 'jobA' +}); + +module.exports = { + start: () => { + const worker = multee.start(__filename) + return { + test: jobA(worker), + worker: worker + } } - return result -}) - -module.exports = () => { - const worker = multee.start(__filename) - return { result: jobA(worker) } } // master.js async function partA() { const worker = require('./worker') - const result = await worker.jobA() + const test = worker.start() + const result = await worker.test() // do the rest with result console.log(result) - // { result: 4950 } + // { result: 'jobA' } + test.worker.terminate() } ``` From 84f3e721999789874b5c052513d8897307f66653 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Sun, 16 Jan 2022 17:42:56 +0200 Subject: [PATCH 2/4] Bug --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 862d500..26a5333 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ module.exports = { async function partA() { const worker = require('./worker') const test = worker.start() - const result = await worker.test() + const result = await test.test() // do the rest with result console.log(result) // { result: 'jobA' } From d7bf9560ca995e993edb8a44676123bd3c0ffdc9 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Sun, 16 Jan 2022 17:51:55 +0200 Subject: [PATCH 3/4] semicolon derp --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26a5333..02432c0 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ const jobA = multee.createHandler('jobA', () => { // do the heavy load here console.log('jobA') return 'jobA' -}); +}) module.exports = { start: () => { From 4a7cd4f3d58ac391f81ba56f5ba60b48116466b5 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Sun, 16 Jan 2022 17:54:31 +0200 Subject: [PATCH 4/4] Work example the same as previously. --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02432c0..88a78bd 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,11 @@ const multee = Multee('worker') // 'worker' for worker_threads | 'child' for chi const jobA = multee.createHandler('jobA', () => { // do the heavy load here - console.log('jobA') - return 'jobA' + let result = 0 + for (let i = 0; i < 100; i++) { + result += heavy_and_return_same(i) + } + return result }) module.exports = { @@ -68,7 +71,7 @@ async function partA() { const result = await test.test() // do the rest with result console.log(result) - // { result: 'jobA' } + // { result: 4950 } test.worker.terminate() } ```