0

I want to make n number of api call and i am doing as floows

   try {
    ....
     yield all(
          action.uploadDocsBody.map(u =>
            call(uploadDocs, {
              ...,

            }),
          ),
        );

     yield put({
      type: UPLOADDOCS_COMPLETED,
      payload: { statusText: 'Success' },
    });

 } catch (e) {

    yield put({
      type: UPLOADDOCS_FAILED,
      payload: {
        error: true,
      },
    });
  }

the issue is that UPLOADDOCS_COMPLETED being called only after finishing all the api calls.

I want to yield put after every api call how can use it ?

NIsham Mahsin
  • 243
  • 2
  • 12

2 Answers2

1

You can wrap each call with another generator, and yield it:

function *foo(u) {
 yield call(uploadDocs, {...});
 yield put({ type: UPLOADEDDOCS_COMPLETED, .....});
}

yield all(action.uploadDocsBody.map(u => foo(u)))
MorKadosh
  • 5,128
  • 3
  • 23
  • 34
1
function call(uploadDocs,{...},callback){
  /// do you task
    callback()
}   
function *foo(u) {
  var put  =  function({ type: UPLOADEDDOCS_COMPLETED, .....});   
 yield call(uploadDocs, {...} ,put);

}
divyang4481
  • 1,203
  • 11
  • 23