1.0.1 • Published 5 years ago

@amphibian/promise-timeout v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@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.