
Security News
Node.js Considers Public Workflow for Security Reports Amid AI-Driven Surge
Node.js is debating whether AI-driven security report volume warrants moving more vulnerability reports into public workflows.
rx-from-async-iterator
Advanced tools
A method to convert AsyncGeneratorObject to Rx.Observable
npm i -S rx-from-async-iterator
import { fromAsyncIterator } from 'rx-from-async-iterator';
import { fromEvent } from 'rxjs';
import { take } from 'rxjs/operators';
const click$ = fromEvent('click', document.body).pipe(take(2));
async function sleepOneSecond() {
return new Promise(r => setTimeout(r, 1000));
}
async function* subTask() {
await sleepOneSecond();
yield "d";
await sleepOneSecond();
yield "e";
await sleepOneSecond();
}
async function* taskAsync(error?: Error) {
yield "a";
await sleepOneSecond();
yield "b";
await sleepOneSecond();
yield "c";
yield* subTask();
yield "f";
yield click$;
}
fromAsyncIterator(taskAsync()).subscribe(console.log);
/// output as follows:
// -> 'a'
// -> 'b'
// -> 'c'
// -> 'd'
// -> 'e'
// -> 'f' /// and one second duration between each letter.
// -> MouseEvent
// -> MouseEvent
Imagine we have an QRCode sign up feature to do, we need to poll an backend interface called /check/login
async function* pollCheckLogin() {
let currentStatus = 'currentStatus';
while(currentStatus === 'pending') {
yield currentStatus = (await fetch('/check/login').then(resp => resp.json)).status;
}
if (currentStatus === 'timeout') {
yield 'timeout';
}
if (currentStatus === 'success') {
yield 'login success';
return;
}
throw new Error('unknown status');
}
fromAsyncIterator(pollCheckLogin()).subscribe((status) => {
switch(status) {
case 'timeout':
// handle timeout
break;
case 'login success':
// go to home page
break;
case 'pending':
// handle pending
break;
}
});
FAQs
Convert asyncGenerator object to Rx.Observable
The npm package rx-from-async-iterator receives a total of 25 weekly downloads. As such, rx-from-async-iterator popularity was classified as not popular.
We found that rx-from-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
Node.js is debating whether AI-driven security report volume warrants moving more vulnerability reports into public workflows.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.