Giter Club home page Giter Club logo

Comments (5)

MichaReiser avatar MichaReiser commented on May 24, 2024

You need to use

import parallel from "parallel-es"

You find an example here using commonjs.

I had to release a new version as it seemed that webpack did not export the default export for some reason. This seems to be fixed with a newer webpack version. So just install the latest version

and you find the api documentation here

Besides, the webpack plugin does not yet work with node.js. So you can use webpack but you don't have to for parallel.es (but you can not use any variables from the outer scope).

from parallel.es.

jefffriesen avatar jefffriesen commented on May 24, 2024

I forgot to mention that I tried import parallel from "parallel-es" already. That was my first attempt. I've had a problem in the past where typescript wanted the * as packagename syntax so that was my last attempt.

I updated to 0.1.18 that you released a few hours ago and range is defined now (along with from, run and times) but now I get this error:

module.js:470 Uncaught Error: Cannot find module './node-slave.parallel'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.resolve (internal/module.js:27:19)
    at NodeWorkerThreadFactory.getSlaveFileName (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:34363)
    at NodeWorkerThreadFactory.value (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:34039)
    at t.value (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:31868)
    at t.value (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:31657)
    at /Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:41100
    at Array.map (native)
    at e.value (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:41056)
    at t.value (/Users/jeffers/git/jefffriesen/parallel-es-node-example/dist/parallel-range.js:85:37653)

But it sounds like the webpack compiling isn't suppose to work yet with node.js. Here is a nice summary of the difference between node.js webpack config and a browser config: http://stackoverflow.com/a/43202748/1884101

What needs to happen to get it to work with node.js?

Also, in node.js, does that mean I can't pass external functions to the function I want to run in parallel? This section in the docs I'm not clear on: https://github.com/MichaReiser/parallel.es#referenced-functions-variables-and-imports. Can I manually do what webpack does? I want to pass in a few lodash functions to the function I want to parallelize. Could I just pass the functions in as arguments?

Thanks

from parallel.es.

MichaReiser avatar MichaReiser commented on May 24, 2024

Using it with webpack is a little bit more complicated for the moment. Just require your module. There is no need to use webpack in a node project. If you intend to use webpack, you need to copy the node-slave.parallel file from node_modules/parallel-es/dist into your dist folder, e.g. by using the copy plugin of WebPack.

However, I suggest you for the moment to just use plain require (or import with babel or TypeScript and compiling down to commonjs style).

Also, in node.js, does that mean I can't pass external functions to the function I want to run in parallel? This section in the docs I'm not clear on:

No, you can't at the moment. Passing in the functions will not be sufficient as lodash makes heavily use of closures that are, and cannot, be supported. There needs to be a transpilation step that includes the used functions. But I never got time to work on supporting node properly.

from parallel.es.

jefffriesen avatar jefffriesen commented on May 24, 2024

@MichaReiser Ok, maybe I made it more complicated than I needed to. Just require functions. That's fine. I ran into other problems that are more appropriate for a different ticket. Thank you.

from parallel.es.

jefffriesen avatar jefffriesen commented on May 24, 2024

For reference for other people, here is a node.js repo that uses typescript compilation and webpack.

This works:

import parallel from "parallel-es"

parallel.range(0, 10)
  .map(value => value * value)
  .subscribe((subresult, taskIndex) => console.log(`The result of the task ${taskIndex} is`, subresult))
  .then(result => console.log(result))

// output:
// The result of the task 6 is [ 36 ]
// The result of the task 8 is [ 64 ]
// The result of the task 3 is [ 9 ]
// The result of the task 9 is [ 81 ]
// The result of the task 7 is [ 49 ]
// The result of the task 1 is [ 1 ]
// The result of the task 4 is [ 16 ]
// The result of the task 0 is [ 0 ]
// The result of the task 5 is [ 25 ]
// The result of the task 2 is [ 4 ]
// [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ]

Here I'm copying the node-slave.parallel.js file into the /dist/ directory: https://github.com/jefffriesen/parallel-es-node-example/blob/master/webpack.config.js#L32-L34

  plugins: [
    new CopyWebpackPlugin([
      {from: './node_modules/parallel-es/dist/node-slave.parallel.js'},
    ]),
  ],

from parallel.es.

Related Issues (20)

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.