Giter Club home page Giter Club logo

Comments (2)

MichalCz avatar MichalCz commented on June 20, 2024 1

Hi @Peterculazh,

That's indeed how Scramjet works, not only that, but also if you have a number of functions these will run immediately chained when some chunks are resolved.

In order to achieve what you want, you need to inform the framework that you want to run the function one by one like this:

DataStream
  .from(parseStream(stream))
  .setOptions({maxParallel: 1})
  .do(async (row: string[]) => {
      console.log(`Reading row - ${row}`);
      // read row
      // perform async request to another endpoint
      // store in db
      rowNumber++;
  })
  .run()

I would however consider the option to run your ops in a slightly different fashion - split up your workflow and see which methods you can run in parallel, and which you shouldn't - you can gain a lot of performance this way.

DataStream
  .from(parseStream(stream))
  .setOptions({maxParallel: 32})
  .map((row: string[]) => {
    console.log(`Reading row - ${row}`);
    // read and return mapped row
  })
  .map(async (row: MappedRow) => {
    // perform async request to another endpoint
  })
  .setOptions({maxParallel: 1})
  .do(async (row: MappedRowWithExtraData) => {
    // store in db
    rowNumber++;
  })
  .run()

You could potentially use batch() for the DB also.

I hope this solves your issue. Do you think there's a place for a special method in the framework for this? Maybe something like uniDo or uniMap or just uni()?

from scramjet.

Peterculazh avatar Peterculazh commented on June 20, 2024

A lot thanks. First example is perfectly run as expected and required. As for parallels, I don't need in my case for parallels due of sensitive data, but I got it, thanks.
As for special method, I think uniDo is good

Feel free to close topic, my problem is solved

from scramjet.

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.