Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
How can I postpone timeouterror by async programming?

I'm reviewing a React test, and I have a problem with asynchronous programming.

The requirements are:

  • It takes 7 minutes to get returned response after requesting data. But, when the response is delayed for 30 seconds, a timeout error will occur.

  • Check the API specs, fulfill these requirements:

    • Use the API that checks the data request progress and make it wait for response.
      • Check the progress every second.

And the API is:

import { rest } from 'msw';

export function handlers() {
  return [
    rest.get('/api/data', getData),
    rest.get('/api/data/progress', getDataProgress),
  ];
};

const getData = async (req, res, ctx) => {
  let wait = req.url.searchParams.get('wait');
  if (wait !== 'no') {
    wait = 'yes';
  }

  try {
    startNewGetData();

    if (wait === 'yes') {
      await Promise.race([waitLastGetData, timeout(minutes(7)), timeoutError(minutes(0.5))]);
    }

    return res(ctx.status(200));
  } catch {
    return res(ctx.status(500));
  }
};
const getDataProgress = (_, res, ctx) => {
  return res(
    ctx.status(200),
    ctx.json({
      hasFinished: hasGetDataFinished,
    })
  );
};

let waitLastGetData = undefined;
let hasGetDataFinished = false;
function startNewGetData() {
  hasGetDataFinished = false;
  waitLastGetData = new Promise(resolve => setTimeout(resolve, minutes(3)));
  waitLastGetData.then(() => (hasGetDataFinished = true));
}

I don't even know what I should first touch. Could you please tell me what I should do to fulfill those requirements?

You might not understand my English well because of my short English, sorry for that.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!