Skip to content

Commit

Permalink
feat!: use built-in AbortController instead of node-abort-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
aikoven committed Jul 21, 2022
1 parent b1a4ea2 commit 9a065e1
Show file tree
Hide file tree
Showing 23 changed files with 1,067 additions and 2,450 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ yarn add abort-controller-x

See
[`AbortController` MDN page](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
Use
[`node-abort-controller`](https://www.npmjs.com/package/node-abort-controller)
to polyfill `AbortController` in NodeJS.
AbortController is
[available in NodeJS](https://nodejs.org/api/globals.html#class-abortcontroller)
since 14.17.

## Abortable Functions

Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
"license": "MIT",
"devDependencies": {
"@types/defer-promise": "^1.0.0",
"@types/jest": "^26.0.14",
"@types/jest": "^28.1.6",
"@types/node": "^14.17.0",
"defer-promise": "^2.0.1",
"jest": "^26.5.0",
"jest": "^28.1.3",
"prettier": "^2.1.2",
"rimraf": "^2.6.3",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3"
},
"dependencies": {
"node-abort-controller": "^1.2.1 || ^2.0.0"
"ts-jest": "^28.0.7",
"typescript": "^4.7.4"
}
}
1 change: 0 additions & 1 deletion src/AbortError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'node-abort-controller';
import {
AbortError,
catchAbortError,
Expand Down
2 changes: 0 additions & 2 deletions src/AbortError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {AbortSignal} from 'node-abort-controller';

/**
* Thrown when an abortable function was aborted.
*
Expand Down
1 change: 0 additions & 1 deletion src/abortable.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'node-abort-controller';
import {abortable} from './abortable';
import {nextTick} from './utils/nextTick';

Expand Down
1 change: 0 additions & 1 deletion src/abortable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {AbortSignal} from 'node-abort-controller';
import {execute} from './execute';

/**
Expand Down
1 change: 0 additions & 1 deletion src/all.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import defer = require('defer-promise');
import {AbortError} from './AbortError';
import {all} from './all';
Expand Down
1 change: 0 additions & 1 deletion src/all.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import {AbortError, isAbortError} from './AbortError';

/**
Expand Down
1 change: 0 additions & 1 deletion src/delay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {execute} from './execute';
import {AbortSignal} from 'node-abort-controller';

/**
* Returns a promise that fulfills after delay and rejects with
Expand Down
1 change: 0 additions & 1 deletion src/execute.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'node-abort-controller';
import defer = require('defer-promise');
import {execute} from './execute';
import {nextTick} from './utils/nextTick';
Expand Down
1 change: 0 additions & 1 deletion src/execute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {AbortError} from './AbortError';
import {AbortSignal} from 'node-abort-controller';

/**
* Similar to `new Promise(executor)`, but allows executor to return abort
Expand Down
1 change: 0 additions & 1 deletion src/forever.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'node-abort-controller';
import {forever} from './forever';
import {nextTick} from './utils/nextTick';

Expand Down
1 change: 0 additions & 1 deletion src/forever.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {AbortSignal} from 'node-abort-controller';
import {execute} from './execute';

/**
Expand Down
1 change: 0 additions & 1 deletion src/race.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import defer = require('defer-promise');
import {AbortError} from './AbortError';
import {race} from './race';
Expand Down
1 change: 0 additions & 1 deletion src/race.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import {AbortError, isAbortError} from './AbortError';

/**
Expand Down
1 change: 0 additions & 1 deletion src/retry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {AbortSignal} from 'node-abort-controller';
import {delay} from './delay';
import {rethrowAbortError} from './AbortError';

Expand Down
1 change: 0 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import {catchAbortError} from './AbortError';

/**
Expand Down
9 changes: 4 additions & 5 deletions src/spawn.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import {spawn} from './spawn';
import {forever} from './forever';
import {delay} from './delay';
Expand All @@ -16,7 +15,7 @@ test('fork manual abort', async () => {
actions.push('fork start');
try {
await forever(signal);
} catch (err) {
} catch (err: any) {
actions.push(`fork abort: ${err.message}`);
}
});
Expand Down Expand Up @@ -56,7 +55,7 @@ test('fork abort on spawn finish', async () => {
actions.push('fork start');
try {
await forever(signal);
} catch (err) {
} catch (err: any) {
actions.push(`fork abort: ${err.message}`);
}
});
Expand Down Expand Up @@ -92,7 +91,7 @@ test('fork abort on spawn error', async () => {
actions.push('fork start');
try {
await forever(signal);
} catch (err) {
} catch (err: any) {
actions.push(`fork abort: ${err.message}`);
}
});
Expand Down Expand Up @@ -139,7 +138,7 @@ test('error thrown from fork', async () => {

try {
await forever(signal);
} catch (err) {
} catch (err: any) {
actions.push(`spawn abort: ${err.message}`);
throw err;
}
Expand Down
1 change: 0 additions & 1 deletion src/spawn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController, {AbortSignal} from 'node-abort-controller';
import {AbortError, catchAbortError, isAbortError} from './AbortError';

export type SpawnEffects = {
Expand Down
1 change: 0 additions & 1 deletion src/waitForEvent.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'node-abort-controller';
import {nextTick} from './utils/nextTick';
import {waitForEvent} from './waitForEvent';

Expand Down
1 change: 0 additions & 1 deletion src/waitForEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {AbortSignal} from 'node-abort-controller';
import {execute} from './execute';

export type EventTargetLike<T> =
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
"lib": ["es2020", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "lib",
Expand Down
Loading

0 comments on commit 9a065e1

Please sign in to comment.