🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

async-iterator-from-rx

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-iterator-from-rx

A tool to convert RxJS style observable stream asyncGenerator

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

async-iterator-from-rx

A tool to convert RxJS style observable stream asyncGenerator.

Motivation

RxJS is not so common compare with async/await and it's hard to learn. This tool can help user who is not so familiar with observable to use observables in async/await way.

npm versionbuildcoverageinstall sizeMINIFIEDMINIFIED + GZIPPED

Install

npm i -S rx-from-async-iterator tslib rxjs

Example

Simple usage

For example, we need to collect 10 user touch points when in some case. And we've already have a click stream. Use asyncIteratorFromRx to convert stream to asyncIterator so that you can use for await ... of syntax to process the stream signal.

import { asyncIteratorFromRx } from "async-iterator-from-rx";
import { fromEvent } from "rxjs";

const click$ = fromEvent("pointerdown", document.body); // A click stream.

async function batchCollectByCount(count: number) {
  const clickTrace: Array<[x: number, y: number]> = [];
  const clickIterator = asyncIteratorFromRx(click$); // Convert click stream to an asyncIterator
  for await (const evt of clickIterator) {
    // use `for await ... of` to scan the click stream
    clickTrace.push([evt.x, evt.y]);
    if (clickTrace.length === count) {
      break;
    }
  }
  return clickTrace;
}

batchCollectByCount(10).then(uploadClickTrace);

Keywords

async iterator

FAQs

Package last updated on 28 Jan 2022

Did you know?

Socket

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.

Install

Related posts