Giter VIP home page Giter VIP logo

Comments (5)

balupton avatar balupton commented on September 25, 2024

I don't believe you can pass a function to the worker, however I'd happily be proven wrong by a PR as this seems a useful addition :-) Upon review we can decide if it makes sense to be part of it or outside of it. Good plan?

from readdir-cluster.

jokeyrhyme avatar jokeyrhyme commented on September 25, 2024

Yep, the documentation mentions JSON, and I can confirm that functions do not survive transit:
https://nodejs.org/api/child_process.html#child_process_event_message

a parsed JSON object or primitive value

I'm playing with some other ideas...

from readdir-cluster.

jokeyrhyme avatar jokeyrhyme commented on September 25, 2024

Okay, so eval() is obviously a non-starter, but I found that I can pass a filePath, and have the worker require() it on the other side. If there is valid JavaScript in the content found at that filePath, and it exports a function, then the worker has no trouble executing it.

I'm not sure this makes sense for your project, and it might even be valuable turning it into a generic cluster-powered iterator. Thanks for the rubber-duck debugging, anyhow. :)

I'll close this unless you really want a PR for this idea.

Side note: you may not necessarily need to use the cluster module, as you don't need port-level load-balancing for this (as you don't even open ports). I wonder if just using the childProcess built-in instead would be faster?

from readdir-cluster.

balupton avatar balupton commented on September 25, 2024

. If there is valid JavaScript in the content found at that filePath, and it exports a function, then the worker has no trouble executing it.

I was suspecting this, perhaps the worker file path can be provided as an option. Such that the user can copy the worker template and modify the stat action to their desire which would more or less accomplish this as needed. It's a bit hacky, but would work.

I'd be more inclined to just boot up another set of workers with the generated file list at the end or on the fly.

I'm not sure this makes sense for your project, and it might even be valuable turning it into a generic cluster-powered iterator. Thanks for the rubber-duck debugging, anyhow. :)

Hehe, no worries.

from readdir-cluster.

jokeyrhyme avatar jokeyrhyme commented on September 25, 2024

In case you were curious, here's what I came up with so far for loading in callbacks via paths:
https://github.com/jokeyrhyme/child-process-async.js

It's missing error handling and worker clean ups, so it's not production-ready, but the concept is there.

from readdir-cluster.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.