Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b26334c
Merge pull request #78 from TENSIILE/master
TENSIILE Apr 15, 2026
1058501
feat: adds internal fetch (#78)
TENSIILE Apr 19, 2026
560f88b
chore(eslint): adds the no-use-before-define rule (#78)
TENSIILE Apr 19, 2026
612630f
chore(jest): adds a polyfill for fetch in a jest environment (#78)
TENSIILE Apr 19, 2026
322e0cb
test(fetch.lib): adds tests for the fetch function (#78)
TENSIILE Apr 19, 2026
fb5f670
adds an example of the provision API (#79)
TENSIILE Apr 20, 2026
3e7c232
test: installs a polyfill package for fetch in a jest environment (#79)
TENSIILE Apr 20, 2026
ab4b1f1
feat(dev): adds setAborterContextProvisionToFetchMode (#79)
TENSIILE Apr 20, 2026
79ae536
feat: adds server breaker headers disabling (#79)
TENSIILE Apr 20, 2026
1682de0
feat(aborter): integrates aborter with the Provision API (#79)
TENSIILE Apr 20, 2026
36b0966
docs(readme): adds documentation for the provision API (#79)
TENSIILE Apr 20, 2026
fd6b138
test: fixes tests with createAbortableHeaders (#79)
TENSIILE Apr 20, 2026
757d058
chore(eslint): removes the no-use-before-define setting (#79)
TENSIILE Apr 20, 2026
48c2e7c
refactor!: renames the headers interface for interruption (#79)
TENSIILE Apr 21, 2026
49326e0
refactor!: fixes integration with Aborter (#79)
TENSIILE Apr 21, 2026
8bc626c
test(setTimeoutAsync): fixes setTimeoutAsync tests (#79)
TENSIILE Apr 21, 2026
f259d44
fix!: fixes debounce integration with Aborter (#79)
TENSIILE Apr 21, 2026
3234807
refactor: removes the check for unpacking arguments before saving the…
TENSIILE Apr 21, 2026
1c63ce8
Merge pull request #79 from TENSIILE/feature/2.4.0-fetch-lib
TENSIILE Apr 21, 2026
9adbc02
feat(isTimeoutError): adds function to determine whether the error is…
TENSIILE Apr 21, 2026
c69e169
docs(isTimeoutError): adds an example of working with isTimeoutError …
TENSIILE Apr 21, 2026
9387b97
test(isTimeoutError): adds tests for isTimeoutError (#80)
TENSIILE Apr 21, 2026
8496307
docs(isTimeoutError): adds changes to the changelog (#80)
TENSIILE Apr 21, 2026
cd8d6bc
Merge pull request #80 from TENSIILE/feature/2.4.0-is-timeout-error
TENSIILE Apr 21, 2026
7b9a6ce
feat(provision-api): integrates XHR with Provision API (#81)
TENSIILE Apr 22, 2026
1a87b51
docs: improves jsdoc for the onAbort EventListener callback (#81)
TENSIILE Apr 22, 2026
0851a13
docs: adds documentation for Provision API (#81)
TENSIILE Apr 22, 2026
53753b9
Merge pull request #81 from TENSIILE/feature/2.4.0-xhr
TENSIILE Apr 22, 2026
b76efef
version upgrade to 2.4.0 (#82)
TENSIILE Apr 23, 2026
3e4ba32
adds an example of version 2.4.0 (#82)
TENSIILE Apr 23, 2026
4e6c31f
docs(readme): updates the documentation for version 2.4.0 of the pack…
TENSIILE Apr 23, 2026
0996363
docs: updates the changelog (#82)
TENSIILE Apr 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Saborter Changelog

## v2.4.0 (April 23th, 2026)

### New Features

- Added `isTimeoutError` function to determine whether the given error is a timeout error [#80](https://github.com/TENSIILE/saborter/pull/82/changes/9adbc0237df3944b21cb60488105b0238d36d10d)
- Added `Provision API` that injects the `Aborter` context into the `Http API` [#81](https://github.com/TENSIILE/saborter/pull/82/changes/7b9a6ce4f8050aceb6c3e1c13d93a42c41b9a497)

## v2.3.0 (April 15th, 2026)

### New Features
Expand Down
35 changes: 33 additions & 2 deletions docs/libs.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ try {
}
```

### `isTimeoutError`

This function determines whether a given error represents a timeout‑induced abort error. It checks that the error is an `AbortError`, its initiator property is exactly `'timeout'`, and its `cause` is an instance of `TimeoutError`. This is useful for distinguishing timeouts from other abort reasons (e.g., user cancellation or system aborts).

**Parameters:**

- `error: any` - The error object to inspect.

**Returns:**

`error is TimeoutError`

- Returns `true` if the error is an `AbortError` with `initiator === 'timeout'` and `cause instanceof TimeoutError`.
- Returns `false` otherwise.

**Example:**

```typescript
try {
await abortableRequest();
} catch (error) {
if (isTimeoutError(error)) {
console.log('Request timed out');
// Handle timeout gracefully
} else {
// Re‑throw other errors
throw error;
}
}
```

### `debounce`

Creates a debounced function that delays invoking the provided handler until after a specified timeout has elapsed since the last call. This is a leading‑edge debounce – the first call in a burst schedules the execution, and subsequent calls reset the timer. The debounced function accepts an `AbortSignal` and returns a promise that resolves with the handler's result or rejects if the handler throws or the signal is aborted.
Expand All @@ -126,7 +157,7 @@ Creates a debounced function that delays invoking the provided handler until aft

**Returns:**

`(signal: AbortSignal) => R | Promise<R>`
`(signal: AbortSignal) => Promise<R>`

A function that accepts an `AbortSignal` and returns a `Promise<R>`, where `R` is the return type of the handler.

Expand Down Expand Up @@ -210,7 +241,7 @@ Schedules the execution of a handler after a specified delay. The operation can

**Parameters:**

- `handler: ((signal: AbortSignal) => T | Promise<T>)`:
- `handler: ((signal: AbortSignal, requestOptions: AbortableRequestOptions) => T | Promise<T>)`:
- A function that accepts an `AbortSignal` and returns a value or a `Promise`. This function will be called with the signal to allow cleanup on abort.
- `delay?: number` - The time in milliseconds to wait before executing the handler. If omitted, the handler is scheduled without a delay (i.e., as soon as possible).
- `options?: Object`:
Expand Down
8 changes: 4 additions & 4 deletions integrations/project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integrations/project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0",
"saborter": "file:../../unreleased-packages/saborter-2.3.0.tgz"
"saborter": "file:../../unreleased-packages/saborter-2.4.0.tgz"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
Expand Down
50 changes: 37 additions & 13 deletions integrations/project/src/app.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ interface User {
name: string;
}

const getUsers = async (signal: AbortSignal) => {
const response = await fetch('https://jsonplaceholder.typicode.com/users', { signal });
interface Post {
id: number;
title: string;
}

return (await response.json()) as { data: User[] };
const getUsers = async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/users');

return (await response.json()) as User[];
};

const getPosts = async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/posts');

return (await response.json()) as Post[];
};

const useAborter = <D,>() => {
Expand All @@ -21,8 +32,6 @@ const useAborter = <D,>() => {
() =>
new Aborter({
onInit: (aborter) => {
console.log('state:', aborter.listeners.state.value);

aborter.listeners.addEventListener('fulfilled', (d) => {
setData(d);
});
Expand All @@ -31,7 +40,7 @@ const useAborter = <D,>() => {
setError(er);
});

aborter.listeners.state.subscribe((s) => {
aborter.listeners.state.subscribe((s: any) => {
setLoading(s === 'pending');
setError(null);
setData(null);
Expand All @@ -44,30 +53,45 @@ const useAborter = <D,>() => {
};

export const App = () => {
const { aborter, data, error, loading } = useAborter<User[]>();
const { aborter: usersAborter, data: users, error, loading } = useAborter<User[]>();
const { aborter: postsAborter, data: posts, loading: postsLoading } = useAborter<Post[]>();

const handleLoad = async () => {
aborter.try(getUsers);
const handlePostsLoad = async () => {
postsAborter.try(getPosts, { timeout: 1000 });
};

const handleCancel = () => aborter.abort();
const handleUsersLoad = async () => {
usersAborter.try(getUsers);
handlePostsLoad();
};

const handleCancel = () => {
postsAborter.abort();
usersAborter.abort();
};

return (
<>
<h1>Saborter Check</h1>
<div className='card'>
<div className='gap-2'>
<button onClick={handleLoad}>Load</button>
<button onClick={handleUsersLoad}>Load</button>
<button onClick={handleCancel}>Cancel</button>
</div>

{loading && <p>Loading...</p>}
{(loading || postsLoading) && <p>Loading...</p>}
{error && <p>{String(error)}</p>}
<ul>
{data?.map((user) => {
{users?.map((user) => {
return <li key={user.id}>{user.name}</li>;
})}
</ul>
<hr />
<ul>
{posts?.map((post) => {
return <li key={post.id}>{post.title}</li>;
})}
</ul>
</div>
</>
);
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const config = {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.ts?$': 'ts-jest'
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
transformIgnorePatterns: ['node_modules'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
Expand Down
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('whatwg-fetch');
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "saborter",
"version": "2.3.0",
"version": "2.4.0",
"description": "A simple and efficient library for canceling asynchronous requests using AbortController",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -110,7 +110,8 @@
"vite": "^7.3.0",
"vite-plugin-circular-dependency": "^0.5.0",
"vite-plugin-clean": "^2.0.1",
"vite-plugin-dts": "^4.5.4"
"vite-plugin-dts": "^4.5.4",
"whatwg-fetch": "^3.6.20"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
Loading
Loading