Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created March 10, 2017 08:07
Show Gist options
  • Select an option

  • Save mohemohe/c1ec20ba2ab9bd18faa9540264b886f9 to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/c1ec20ba2ab9bd18faa9540264b886f9 to your computer and use it in GitHub Desktop.
fetchAPIにタイムアウトがないのでawaitしたときに死ぬからつらい
new Promise(async(resolve, reject) => {
let timeoutHendle = setTimeout(() => {
reject();
}, 5000);
let response: Response = null;
if (init == null) {
response = await fetch(input);
} else {
response = await fetch(input, init);
}
clearTimeout(timeoutHendle);
resolve(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment