Skip to content

Commit

Permalink
Update default timeout in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Jan 5, 2024
1 parent 444394b commit 5cd081d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -10,6 +10,7 @@ import { HardenedFetch } from 'hardened-fetch'
const client = new HardenedFetch({
baseUrl: 'https://swapi.dev/api/',
})

const response = await client.fetch('/species/1/')
```

Expand Down Expand Up @@ -71,7 +72,7 @@ const client = new HardenedFetch({
})
```

### `client.fetch(url, [init] = {}, [timeout] = 9000)`
### `client.fetch(url, [init] = {}, [timeout] = 30000)`

Expects a `url` to the resource that you wish to fetch and optionally custom [settings](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) to apply to the request, and a timeout in milliseconds. Returns a promise which will resolve with the [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object when successful. Rejects with a relevant [HTTP error](https://www.npmjs.com/package/http-errors) on failure.

Expand All @@ -80,7 +81,7 @@ const response = await client.fetch('https://swapi.dev/api/species/1/')
const json = await response.json()
```

### `client.paginatedFetch(url, [options] = {}, [timeout] = 9000)`
### `client.paginatedFetch(url, [options] = {}, [timeout] = 30000)`

Expects a `url` to the resource that you wish to fetch and optionally custom [settings](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) to apply to the request, and a timeout in milliseconds. Returns an [`AsyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator) which will resolve with a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object and `done` property on each successful iteration. Rejects with a relevant [HTTP error](https://www.npmjs.com/package/http-errors) on failure.

Expand Down
4 changes: 2 additions & 2 deletions src/HardenedFetch.ts
Expand Up @@ -33,7 +33,7 @@ export class HardenedFetch {
this.queue.on('failed', handleFailed.bind(null, this.options))
}

fetch(url: string, init: RequestInit = {}, timeout: number = 30000) {
fetch(url: string, init: RequestInit = {}, timeout: number = 30_000) {
if (this.options.baseUrl && !url.startsWith('http')) {
url = join(this.options.baseUrl, url)
}
Expand All @@ -46,7 +46,7 @@ export class HardenedFetch {
return this.queue.schedule(makeRequest, url, init, timeout)
}

async *paginatedFetch(url: string, init: RequestInit = {}, timeout: number = 9000) {
async *paginatedFetch(url: string, init: RequestInit = {}, timeout: number = 30_000) {
let nextUrl: string | null = url

while (nextUrl) {
Expand Down

0 comments on commit 5cd081d

Please sign in to comment.