Skip to content

Commit

Permalink
fix(fetch): timeout fetch if no response from the server
Browse files Browse the repository at this point in the history
based on suggestion on JakeChampion/fetch#175
  • Loading branch information
Jun711 committed Jan 13, 2018
1 parent fd5bd10 commit 5a266bd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/util/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function timeout(promise, ms = 30000) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('timeout'))
}, ms)
promise.then(resolve, reject)
})
}

0 comments on commit 5a266bd

Please sign in to comment.