superagent icon indicating copy to clipboard operation
superagent copied to clipboard

retry async function not working

Open dpanic opened this issue 4 years ago • 1 comments

Hi if I implement retry with async callback function. Async sleep will not work. But if I do it this way:

          .retry(3, (err) => {
            if (err) {
              log.error(err, module, 'Retrying request');

              // sleep sync
              // important: don't remove this, async solution will not work!!!
              Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 2 * 1000);
              return true;
            }

            return false;
          })

All works. Does this look like good solution to you? Apart of it this is blocking worker thread.

dpanic avatar Nov 04 '21 13:11 dpanic

PR welcome to fix this - perhaps start by adding at test that fails?

niftylettuce avatar Jan 17 '22 23:01 niftylettuce