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

Support for worker threads #147

Open
ncroese opened this issue Apr 2, 2020 · 1 comment
Open

Support for worker threads #147

ncroese opened this issue Apr 2, 2020 · 1 comment

Comments

@ncroese
Copy link

ncroese commented Apr 2, 2020

The library does not seem to work inside a worker thread. When running the code below the result is not logged:

const { Worker, isMainThread } = require("worker_threads");
if (isMainThread) {
    const worker = new Worker(__filename);
    worker.on("error", error => console.log(error));
    worker.on("exit", code => console.log(`Exit: ${code}`));
} else {
    const { Magic, MAGIC_MIME_TYPE } = require("mmmagic");
    const buffer = Buffer.from("plain text");
    const magic = new Magic(MAGIC_MIME_TYPE);
    magic.detect(buffer, (error, result) => {
        if (error) {
            throw error;
        }
        console.log(`Result: ${result}`);
    });
}

I'm assuming something breaks inside the library code because it's not compatible with worker threads yet, since running the same code on the main thread works just fine. Would you be willing to make the library compatible with worker threads? Sadly I don't have the knowledge to do this myself.

@tnabil
Copy link

tnabil commented Mar 9, 2023

Hi @ncroese,
The logging issue you're facing is probably related to this Node bug related to worker threads: nodejs/node#30491
This is not to say that your feature request is not valid, it definitely is, but the logging issue could be a separate one.

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

No branches or pull requests

3 participants