feat: support multiple functions per worker
[poolifier.git] / examples / multifunctionWorker.js
index 61369cfa57171d2cc26c5028cd170e4cd51cf9c7..a38d8bb0872e82658abac89a01408d37f6983960 100644 (file)
@@ -1,14 +1,14 @@
 'use strict'
 const { ThreadWorker } = require('poolifier')
 
-function yourFunction (data) {
-  if (data.functionName === 'fn0') {
-    console.log('Executing function 0')
-    return { data: '0 your input was' + data.input }
-  } else if (data.functionName === 'fn1') {
-    console.log('Executing function 1')
-    return { data: '1 your input was' + data.input }
-  }
+function fn0 (data) {
+  console.log('Executing function 0')
+  return { data: 'fn0 your input was' + data.text }
 }
 
-module.exports = new ThreadWorker(yourFunction)
+function fn1 (data) {
+  console.log('Executing function 1')
+  return { data: 'fn1 your input was' + data.text }
+}
+
+module.exports = new ThreadWorker({ fn0, fn1 })