Skip to content

gershy/utilRetry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retry

Overview

Allows retrying an arbitrary operation.

const data = await retry({
  attempts: 5,
  delay: n => n * n * 100, // Interpreted as milliseconds
  fn: () => {
    const res = await fetch('https://flaky-host.com/api/data');
    if (res.status >= 500) throw Error('host flaked')[mod]({ retry: true });
    
    const json = await res.json();
    if (json === `we're experiencing problems sorry`)
      throw Error('unreliable host flaked')[mod]({ retry: true });
    
    return json;
  },
  retryable: err => !!err.retry
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors