Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pool.exec(<function>) fails to emit message event to the pool. #439

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

w1nklr
Copy link
Contributor

@w1nklr w1nklr commented Apr 2, 2024

When using worker-pool in a browser environment, worker function registration does not work. Only pool.exec(<function>) can be run, but does not handle the on message callbacks.

This fix proposes to send the pool.exec options to the execution script.

Referenced doc: https://github.com/josdejong/workerpool#events
Playground: https://codesandbox.io/p/sandbox/workerpool-in-a-react-project-forked-dgjxxc

Possible fix for issue #438

When using worker-pool in a browser environment, worker function registration does not work.
Only `pool.exec(<function>)` can be run, but does not handle the on message callbacks

Referenced doc: https://github.com/josdejong/workerpool#events
Playground: https://codesandbox.io/p/sandbox/workerpool-in-a-react-project-forked-dgjxxc
@josdejong
Copy link
Owner

Thanks @t0oF-azpn for reporting this issue and working out a fix!

Would it be possible to write a unit test to ensure we can't get any regressions in the future?

@w1nklr
Copy link
Contributor Author

w1nklr commented Apr 3, 2024

Thanks @t0oF-azpn for reporting this issue and working out a fix!

Would it be possible to write a unit test to ensure we can't get any regressions in the future?

I tried first to add/update the unit tests. But I didn't manage to make it run.
In this particular case, we need to be in browser context. I tried to force to use web workers (var pool = createPool({ workerType: 'web' });), but this fails at worker creation in ensureWebWorker() function.

If there is any way to set the test to web browser context, I would take it ;)

@josdejong
Copy link
Owner

OK let's just merge this PR as is, ok? The fix makes sense.

I do think though that referring to worker in a standalone function is a bit of a tricky case: you're relying on an undocumented global variable exposed by a library. The neat solution would be to create a dedicated worker where you import worker explicitly.

@w1nklr
Copy link
Contributor Author

w1nklr commented Apr 4, 2024

I'm fine with merging This PR as is !
I don't have the rights to do it, though ;)

@josdejong
Copy link
Owner

👍 I'll merge and publish your PR first half of next week.

@josdejong josdejong merged commit aef7e7d into josdejong:master Apr 6, 2024
3 checks passed
@josdejong
Copy link
Owner

I found a moment, just published v9.1.1 containing your fix. Thanks again!

@w1nklr w1nklr deleted the fix_webworker_callbacks branch April 8, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants