【文件属性】:
文件名称:timeout-after.js:轻松将超时添加到任何功能
文件大小:3KB
文件格式:ZIP
更新时间:2021-05-25 10:18:41
JavaScript
将超时添加到现有函数。
timeout-after使用全局Promise因此您可能必须为节点进行polyfill。
安装
npm install timeout-after
用法
从现有功能创建一个新功能:
import timeoutAfter from 'timeout-after' ;
const fetchWithTimeout = timeoutAfter ( 5000 , fetch ) ;
// The new function will return a promise, which gets rejected if it takes too
// long.
( async function ( ) {
try {
await fetchWithTimeout ( ... ) ;
} catch ( err ) {
if ( err . n
【文件预览】:
timeout-after.js-master
----.gitignore(15B)
----package.json(694B)
----LICENSE(1KB)
----index.js(1KB)
----README.md(777B)
----tests.js(1001B)