Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@toebeann/procedure.js",
"version": "0.1.0",
"version": "0.2.0",
"description": "A simple RPC framework, built on top of nanomsg and msgpack.",
"main": "./dist/index",
"types": "./types/index.d.ts",
"author": "Tobey Blaber (https://github.com/toebeann)",
"homepage": "https://github.com/toebeann/procedure.js",
"repository": "github:toebeann/procedure.js",
"funding": "https://paypal.me/tobeyblaber",
"license": "UNLICENSED",
Expand All @@ -13,7 +14,7 @@
"build": "tsc",
"lint": "eslint . --ext .ts",
"test": "mocha -r ts-node/register -r source-map-support/register ./test/**/*.ts",
"test:coverage": "nyc npm run test"
"test:coverage": "npm run build & nyc npm run test"
},
"dependencies": {
"@msgpack/msgpack": "^2.7.2",
Expand All @@ -28,7 +29,7 @@
"@types/chai-as-promised": "^7.1.5",
"@types/chai-spies": "^1.0.3",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.3",
"@types/node": "^18.6.3",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
Expand Down
36 changes: 36 additions & 0 deletions src/aggregate-signal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { isSignal } from './utils';

/**
* A helper class to create an AbortSignal which aborts as soon as any of the signals passed to its constructor do.
*/
export default class AggregateSignal {
/** The aggregate AbortSignal. */
public readonly signal?: AbortSignal;

/**
* Initializes a new AggregateSignal.
* @param {(AbortSignal | undefined)[]} abortSignals The AbortSignals to aggregate.
*/
constructor(...abortSignals: (AbortSignal | undefined)[]) {
const signals = abortSignals.filter(isSignal);

if (signals.length === 1) {
this.signal = signals[0];
} else if (signals.filter(s => s.aborted).length > 0) {
this.signal = signals.filter(s => s.aborted)[0];
} else if (signals.length > 1) {
const ac = new AbortController();
this.signal = ac.signal;

for (const signal of signals) {
signal.addEventListener('abort', () => {
for (const signal of signals) {
signal.removeEventListener('abort');
}

ac.abort();
});
}
}
}
}
Loading