ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

retry async function not working #1648

Open dpanic opened 2 years ago

dpanic commented 2 years ago

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.

niftylettuce commented 2 years ago

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