
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
event-target-to-async-iter
Advanced tools
Takes an event target and an event name and turns it into an async iterable
Takes an EventTarget
and an event name and turns it into an async iterable.
Note that the async iterable will not complete until either
return
function is called, orreturnEvent
is provided and gets dispatched on the event target.Waiting for web socket messages:
const socket = new WebSocket('wss://example.com/socketserver');
const iter = eventTargetToAsyncIter(socket, 'message', {
returnEvent: 'close'
});
for await (const message of iter) {
console.log(message)
}
Say you have a heavily callback-based API such as HTMLRewriter and would prefer to process it as an async iterable. You can use a custom event target and eventTargetToAsyncIter
:
const target = new EventTarget();
const iter = eventTargetToAsyncIter(target, 'data');
// Helper function that consumes a readable stream
async function swallow(stream) {
const reader = stream.getReader();
while (await reader.read().then(x => !x.done)) {}
}
const response = new HTMLRewriter()
.on('.athing[id]', {
element(el) {
target.dispatchEvent(new CustomEvent('data', {
detail: el.getAttribute('id'),
}));
}
})
.transform(await fetch('https://news.ycombinator.com'));
// No await here
swallow(response.body)
.then(() => iter.return()) // Don't create an endless loop
.catch(e => iter.throw(e)) // Don't swallow errors
for await (const event of iter) {
const id = Number(event.detail);
console.log(id);
}
FAQs
Takes an event target and an event name and turns it into an async iterable
The npm package event-target-to-async-iter receives a total of 2 weekly downloads. As such, event-target-to-async-iter popularity was classified as not popular.
We found that event-target-to-async-iter 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
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket investigates hidden protestware in npm packages that blocks user interaction and plays the Ukrainian anthem for Russian-language visitors.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.