0

I want to send a bulk of data and after completing it, want to move to the next one. For example: I have this function:

async function test() {
  await sample.sampleStructure()
  await sample.sampleDataAdd()
  await sample.sampleDataGet()
}

Where I am calling the 3 functions for each call. But I wanted to send for example 200 data for await sample.sampleDataAdd() and if the first 200 data response is 'Success' then it will send the rest of the 200 datas. After completing 1000 datas, I want to move on to the next function call. So I looked and I think RXJS can provide the solution. But I am not use if is it possible to use the filter and next for this scenario.

async function test() {
  await sample.sampleStructure()
  // let observable = Observable.range(1,1000)
  let observable = Observable.create()
  observable
  .filter(aysnc function () {
    await sample.sampleDataAdd()
   })
  .subscribe({
    .next: async function () {
       // await sample.sampleDataAdd()
    },
    .error: function (error) {
      console.log(error)
     }
   })

I am very new at rxjs, so there are lots of mistakes as well. Please can anyone help me regarding this matter ?

lazysnoozer
  • 85
  • 11

1 Answers1

0

You can use Promise.all to run jobs in parallel

const job1Result = await job1()
const job2 = sample.sampleStructure2()
const job3 = sample.sampleStructure3()
const job4 = sample.sampleStructure4()
const [job2Result, job3Result, job4Result] = await Promise.all([job2, job3, job4])

const job5 = await job5()


you could then create a loop that goes through 10 at a time.

If you are going to introduce rxjs, there is a lot more to learn. and handling rxjs subscriptions and error handling can be quite daunting. So before you introduce it, try to solve it without it.

Leon Radley
  • 7,596
  • 5
  • 35
  • 54
  • I understand. But in parallel promise, I cant send bulk data in specific function. for example: I want job2 to run 10000 times whereas job1, job3 should be called only once. – lazysnoozer Apr 27 '20 at 04:11