Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
async-broadcaster
Advanced tools
Readme
Observable alternative using async iterators
npm i async-broadcaster
It's a common requirement to let users subscribe to new values that are produced asynchronously. Often we reach for an observable library (RxJS, zen-observable, Wonka, etc.) to manage subscriptions and allow broadcasting of new values, but full observable implementations may be overkill for simple subscriptions. Observable also bring along a new API, when JavaScript already has an standard API for consuming asynchronous values: async iterables.
What's needed to enable consumers to use async iterables is a way for producers to make async iterables that can be listened to by multiple listeners and correctly handle buffering, unsubscription, etc.
This is what AsyncBroadcaster does.
AsyncBroadcaster takes a single async iterable and adapts it to allow multiple listeners.
import {AsyncBroadcaster} from 'async-broadcaster';
async function* makeOneHundred() {
for (let i = 0; i < 100; i++) {
yield i;
}
}
const broadcaster = new AsyncBroadcaster(makeOneHundred());
// listen to broadcast values
logValues(broadcaster.iterable);
// We can listen more than once
logValues(broadcaster.iterable);
async function logValues(iterable) {
// listening is done with anything that can consume async iterables, like
// a for/await-of loop:
for await (const o of iterable) {
console.log(o);
}
}
Async iterables don't have the functional methods that Array does like map()
, reduce()
, or filter()
, nor the common reactive operators like count()
, zip()
, etc.
These can be imported from a library that works with any async iterable, such as IxJS.
import { filter, map } from 'ix/asynciterable/operators';
const results = from(broadcaster.iterable).pipe(
filter(async x => x % 2 === 0),
map(async x => x * x)
);
for await (let item of results) {
console.log(`Next: ${item}`);
}
FAQs
Observable alternative using async iterators
The npm package async-broadcaster receives a total of 0 weekly downloads. As such, async-broadcaster popularity was classified as not popular.
We found that async-broadcaster 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.