它没有指定的默认值。该规范根本没有讨论超时。
通常,您可以为承诺实现自己的超时包装器:
// Rough implementation. Untested.function timeout(ms, promise) { return new Promise(function(resolve, reject) { setTimeout(function() { reject(new Error("timeout")) }, ms) promise.then(resolve, reject) })}timeout(1000, fetch('/hello')).then(function(response) { // process response}).catch(function(error) { // might be a timeout error})
如https://github.com/github/fetch/issues/175中所述
(https://github.com/mislav)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)