Skip to content

Instantly share code, notes, and snippets.

View RyanChill94's full-sized avatar
🎯
Focusing

Ryanchill RyanChill94

🎯
Focusing
  • ByteDance
  • beijing
View GitHub Profile
{
"scripts": {
"dev": "webpack-dev-server --hot --open",
"dist": "rm -rf public && NODE_ENV=production webpack --config webpack-dist.config.js --display-optimization-bailout",
"jbdist": "tnpm i && NODE_ENV=production webpack --config webpack-dist.config.js"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"badjs-report": "^1.3.2",
"classnames": "^2.2.5",
@RyanChill94
RyanChill94 / fetchWithTimeout.js
Last active August 6, 2018 06:38
timeout checking
const delay = (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('timeout'))
}, ms)
})
}
const fetchWithTimeout = (timeout, ...args) => {
return Promise.race([fetch(...args), delay(timeout)]) // decided by the first promise resolve