PortBlueSky / thread-puddle

A library to pool Node.js worker threads, automatically exposing exported module methods using Proxy Objects. :rocket:
15 stars 3 forks source link

Callback Functions #21

Closed kommander closed 1 year ago

kommander commented 1 year ago

Implements functions, which allows to specify callbacks/functions in the first level of worker method arguments. These functions will be executed on the main thread.

// main.ts
const worker = await createThreadPool(`./worker.ts`)
const closure = 'World'
const callback = () => { console.log(`Hello ${closure}`) }
await worker.someMethod(callback)
// worker.ts
export default {
  someMethod(callback: Function) {
    callback()
  }
}

TODO: