erikras / redux-promise-listener

A Redux middleware that allows actions to be converted into Promises
MIT License
44 stars 11 forks source link

Multiple requests get resolved with the first one which succeeds #13

Open stefanfrede opened 6 years ago

stefanfrede commented 6 years ago

If I fire up multiple requests where each request takes some time before it gets resolved all requests are getting resolved with the first request which succeeds.

async getUser(request) {
  return new Promise(resolve => {
    const generatedAsyncFunction = promiseListener.generateAsyncFunction({
      start: 'START_ACTION_TYPE',
      resolve: 'RESOLVE_ACTION_TYPE',
      reject: 'REJECT_ACTION_TYPE'
    });

    generatedAsyncFunction.asyncFunction({ request }).then(
      resolvePayload => {
        resolve(resolvePayload);
      },

      rejectPayload => {
        resolve(rejectPayload);
      }
    )
  });
};

// All requests are getting resolved with A
getUser('A').then(console.log);
getUser('B').then(console.log);
getUser('C').then(console.log);
mattoni commented 5 years ago

I also am running into this issue. Would be good if we could pass a conditional to resolve based on the payload (i.e. an ID has to match the id that was in the original action)

chmanie commented 5 years ago

I am working on something like this. Given the little activity here I am considering to release the fork as a separate package on npm. Did the author move on to something else?

chmanie commented 5 years ago

Take a look at this fork: https://github.com/JoinColony/redux-promise-listener/commit/db4175d03d289b8fc8a66fe515767a074d130f59

This maintains compatibility to the current usage of this module.

What you will have to do is passing through the meta property in your sagas if in the cases where you need it (there’s just no way around that), like in this module (which does a similar thing): https://github.com/diegohaz/redux-saga-thunk#usage