@amphibian/promise-timeout
v1.0.1
Published
promise timeouts
Downloads
6
Readme
@amphibian/promise-timeout
promise timeouts
npm install @amphibian/promise-timeout
Usage
import timeout from '@amphibian/promise-timeout';
async function getUsers() {
const response = await timeout(fetch('https://reqres.in/api/users'));
const user = await response.json();
return user;
}
With options
const request = fetch('https://reqres.in/api/users')
.then((response) => response.json());
timeout(request, {timeout: 2000});
timeout(function, options)
function
(Function
)
The function to timeout. Should return a Promise
or be async
.
options
(Object
)
options.timeout
(Number
)
Default: 500
Number of milliseconds to wait before throwing an error.