
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Halt a process of asynchronous steps using an AbortSignal.
JavaScript is single-threaded, which means you can't really halt a running process.
However, it provides us an API called AbortController that is basically usable only in specific
scenarios and APIs, such as fetch and addEventListener.
If you want to use the AbortController API in your code, you need to wait for each function to
finish, and check between the function runs whether the AbortSignal has been aborted.
This is a tedious task, and it can be easily forgotten:
const controller = new AbortController();
async function processData() {
const result1 = await heavyDataProcessing(data, controller.signal);
if (controller.signal.aborted) {
return;
}
const result2 = await heavyDataProcessing(result1, controller.signal);
if (controller.signal.aborted) {
return;
}
const result3 = await heavyDataProcessing(result2, controller.signal);
if (controller.signal.aborted) {
return;
}
const result4 = await heavyDataProcessing(result3, controller.signal);
if (controller.signal.aborted) {
return;
}
return result4;
}
button.addEventListener('click', () => {
controller.abort();
});
Abortium solves this problem by letting you create a process of asynchronous steps that
will be halted when the AbortSignal is aborted. It uses the AbortController API under
the hood, and provides a more convenient API to use:
import { abortableProcess } from 'abortium';
const controller = new AbortController();
async function processData() {
const process = abortableProcess(controller.signal)
.then((_, signal) => heavyDataProcessing(data, signal))
.then((result1, signal) => heavyDataProcessing(result1, signal))
.then((result2, signal) => heavyDataProcessing(result2, signal))
.then((result3, signal) => heavyDataProcessing(result3, signal));
const finalResult = await process.execute();
return finalResult;
}
It's somewhat similar to the Promise API. You chain the steps using .then(), and the
library gives you the previous step's result and the AbortSignal as arguments.
Each step in the chain is typed, so the next step will have the correct type for the previous step's result.
When the AbortSignal is aborted, the process will be halted, and all queued steps will be
skipped.
FAQs
Halt a process of asynchronous steps using an AbortSignal
We found that abortium demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.