score:0

here is an example how to use onlylastrequestedpromise:

const makinganapicall = async (url, last = x => x) => {
  let response;
  try {
    response = await last(axios({ url, method: get }));
  } catch (e) {
    if (e === 'a newer request was made.') {
      //ignore this error, current request replaced
      //  with newer one
      return;
    }
    //something else went wrong, rethrow the error
    throw e;
  }
  if (response.status) {
    apiinprogresscheckfn(false, url);
    if (
      response.status === 200 ||
      response.status === 201
    ) {
      dispatch(success(response));
    } else {
      dispatch(failed(response));
    }
  }
};
//iife to initialize last only once
const lastsearchapiresult = (() => {
  const last = onlylastrequestedpromise('search');
  return url => makinganapicall(url, last);
})();

Related Query

More Query from same tag