
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
abortable-iterator
Advanced tools
Make any iterator or iterable abortable via an AbortSignal
The AbortController is used in the fetch API to abort in flight requests from, for example, a timeout or user action. The same concept is used here to halt iteration of an async iterator.
npm install abortable-iterator
import { abortableSource } from 'abortable-iterator'
// An example function that creates an async iterator that yields an increasing
// number every x milliseconds and NEVER ENDS!
const asyncCounter = async function * (start, delay) {
let i = start
while (true) {
yield new Promise(resolve => setTimeout(() => resolve(i++), delay))
}
}
// Create a counter that'll yield numbers from 0 upwards every second
const everySecond = asyncCounter(0, 1000)
// Make everySecond abortable!
const controller = new AbortController()
const abortableEverySecond = abortableSource(everySecond, controller.signal)
// Abort after 5 seconds
setTimeout(() => controller.abort(), 5000)
try {
// Start the iteration, which will throw after 5 seconds when it is aborted
for await (const n of abortableEverySecond) {
console.log(n)
}
} catch (err) {
if (err.code === 'ERR_ABORTED') {
// Expected - all ok :D
} else {
throw err
}
}
import {
abortableSource,
abortableSink,
abortableTransform,
abortableDuplex
} from 'abortable-iterator'
abortableSource(source, signal, [options])abortableSink(sink, signal, [options])abortableTransform(transform, signal, [options])abortableDuplex(duplex, signal, [options])abortableSource(source, signal, [options])(alias for abortable.source(source, signal, [options]))
Make any iterator or iterable abortable via an AbortSignal.
| Name | Type | Description |
|---|---|---|
| source | Iterable|Iterator | The iterator or iterable object to make abortable |
| signal | AbortSignal | Signal obtained from AbortController.signal which is used to abort the iterator. |
| options | Object | (optional) options |
| options.onAbort | Function | An (async) function called when the iterator is being aborted, before the abort error is thrown. Default null |
| options.abortMessage | String | The message that the error will have if the iterator is aborted. Default "The operation was aborted" |
| options.abortCode | String|Number | The value assigned to the code property of the error that is thrown if the iterator is aborted. Default "ABORT_ERR" |
| options.returnOnAbort | Boolean | Instead of throwing the abort error, just return from iterating over the source stream. |
| options.onReturnError | Function | When a generator is aborted, we call .return on it - if this function errors the error value will be passed to the .onReturnError callback if passed. Default null |
| Type | Description |
|---|---|
Iterable | An iterator that wraps the passed source parameter that makes it abortable via the passed signal parameter. |
The returned iterator will throw an AbortError when it is aborted that has a type with the value aborted and code property with the value ABORT_ERR by default.
abortableSink(sink, signal, [options])The same as abortable.source except this makes the passed sink abortable. Returns a new sink that wraps the passed sink and makes it abortable via the passed signal parameter.
abortableTransform(transform, signal, [options])The same as abortable.source except this makes the passed transform abortable. Returns a new transform that wraps the passed transform and makes it abortable via the passed signal parameter.
abortableDuplex(duplex, signal, [options])The same as abortable.source except this makes the passed duplex abortable. Returns a new duplex that wraps the passed duplex and makes it abortable via the passed signal parameter.
Note that this will abort both sides of the duplex. Use duplex.sink = abortable.sink(duplex.sink) or duplex.source = abortable.source(duplex.source) to abort just the sink or the source.
it-pipe Utility to "pipe" async iterables togetherFeel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
FAQs
Make any iterator or iterable abortable via an AbortSignal
The npm package abortable-iterator receives a total of 6,521 weekly downloads. As such, abortable-iterator popularity was classified as popular.
We found that abortable-iterator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.