Skip to content

How would you do an async worker? #5

Description

@LaughingBubba

When I run this:

import { Pool } from 'node-multiprocess'

async function main () {
	const pool = new Pool(4)
	
	async function worker (x) {
		return new Promise( (resolve, reject) => {
		    resolve(x * x)	
		})
	}
	
	const workQ = []
	for (let i = 1; i < 6; i++) {
		const res = pool.addJob(await worker, i)
		workQ.push(res)
	}
	
	const results = await Promise.all(workQ)
	results.forEach(result => console.log(result))
	pool.kill()	
}

main()

I get a bunch of empty opbjects {} which are I assume the unfulfilled promises.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions