MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
940 stars 279 forks source link

[Improvement]: implementation of delay function without setTimeout #585

Closed jeevan-jp closed 1 year ago

jeevan-jp commented 1 year ago

Since setTimeout doesn't guarantee the delay of specified ms, the implementation of delay function in index.js can be improved with the help of while loop.

function delay(ms) {
  return new Promise((resolve) => {
    const now = new Date().getTime();
    while (new Date().getTime() < now + ms) {
      /* Do nothing */
    }
    resolve(null); 
  });
}

Reference Reading: https://www.gimtec.io/articles/settimeout-does-not-guarantee-time-to-execution/

lpinca commented 1 year ago

I'm closing this as per https://github.com/MONEI/Shopify-api-node/pull/586#issuecomment-1458841811.