Skip to content

Instantly share code, notes, and snippets.

@Drag13
Created November 30, 2022 10:09
Show Gist options
  • Select an option

  • Save Drag13/20b83773a25bbb3c15c7ef241595c692 to your computer and use it in GitHub Desktop.

Select an option

Save Drag13/20b83773a25bbb3c15c7ef241595c692 to your computer and use it in GitHub Desktop.
const data = { userName: "test user" };
const delay = 1200;
const errorChance = 0.2;
export function fetchData() {
return new Promise((rs, rj) => {
setTimeout(
() =>
Math.random() > errorChance ? rs(data) : rj("Something went wrong"),
delay
);
});
}
fetchData().then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment