![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
break-async-iterator
Advanced tools
Problem:
const neverResolves /*(without user input)*/ = process.stdin /* (Readable is an async iterator as of Node v10) */
async function* stuck() {
for await (const i of neverResolves) {
yield // never reaches
}
}
let i = stuck()
i.next() // stuck
i.return() // still stuck
Solution
const breakAI = require('break-async-iterator')
const notStuck = breakAI(breakable => async function*() {
try {
for await (const i of breakable(neverResolves)) {
yield
}
} finally {
// reaches when `i.return()` or `i.throw()` is called
}
})
let i = notStuck()
i.next() // still stuck
i.return() // but at least this can break the for-await loop
npm i break-async-iterator
breakAI(breakable => async function* asyncGenerator(){...})
breakable
A function that takes an iterator or a promise and returns a breakable version of the same
Returns An async generator that returns an iterator (wrapped around the one returned by asyncGenerator()
) that's able to interrupt any iterators or promises (that were passed through breakable()
) when its .return()
or .throw()
are called
If you have an async generator function like this:
async function* asyncGenerator() {
for await (const value of anotherAsyncIterator) {
yield value
}
yield await aPromise
}
Then simply wrap it like this
const asyncGenerator = breakAI(breakable => async function*() {
// and wrap any inner asyncIterators or promises with breakable:
for await (const value of breakable(anotherAsyncIterator)) {
yield value
}
yield await breakable(aPromise)
})
FAQs
Break async iterator
The npm package break-async-iterator receives a total of 1 weekly downloads. As such, break-async-iterator popularity was classified as not popular.
We found that break-async-iterator 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.