Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@basic-streams/of-many

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@basic-streams/of-many

ofMany operator for basic-streams

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@basic-streams/of-many

ofMany<T>(
  values: Iterable<T>,
  interval?: number,
  scheduler?: (time: number) => Stream<void>
): Stream<T>

Creates a stream containing given values.

import ofMany from "@basic-streams/of-many"

ofMany([1, 2, 3])(x => {
  console.log(x)
})

// > 1
// > 2
// > 3

If an interval is provided the events will be spread in time by that ammount of milliseconds, with the first one delayed. If the interval is 0 the events will be produced as soon as possible but still asynchronously.

import ofMany from "@basic-streams/of-many"

ofMany([1, 2, 3], 5000)(x => {
  console.log(x)
})

// > 1
// > 2
// > 3

// ____1____2____3

Note that the iterable is consumed lazily, meaning that next() is called only when value is needed.

import ofMany from "@basic-streams/of-many"

function* generator() {
  const startTime = Date.now()
  yield Date.now() - startTime
  yield Date.now() - startTime
  yield Date.now() - startTime
}
ofMany(generator(), 5000)(x => {
  console.log(x)
})

// > 0
// > 5000
// > 10000

//     0   5000  10000
// ____.____.____.

You can provide a custom scheduler, a function that creates a stream producing an event after the given time. By default later is used as a scheduler.

import ofMany from "@basic-streams/of-many"
import later from "@basic-streams/later"

function scheduler(time) {
  return later(time / 2)
}
ofMany([1, 2, 3], 6000, scheduler)(x => {
  console.log(x)
})

// > 1
// > 2
// > 3

// __1__2__3

Keywords

basic-streams

FAQs

Package last updated on 09 Jul 2018

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