New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@basic-streams/from-iterable

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@basic-streams/from-iterable - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

package.json
{
"name": "@basic-streams/from-iterable",
"version": "0.0.5",
"version": "0.0.6",
"description": "fromIterable operator for basic-streams",

@@ -5,0 +5,0 @@ "keywords": [

@@ -13,18 +13,7 @@ # [@basic-streams](https://github.com/rpominov/basic-streams)/from-iterable

Given an `iterable`, returns a stream that produces items from that iterable. If
an `interval` is provided the items will be spread in time. Interval is a number
of milliseconds by which items should be spread. The first item also will be
delayed by that interval. If the interval is `0` the items will be produced as
soon as possible but still asynchronously.
Transforms an `iterable` into a stream.
Also, you can provide a custom `scheduler`, a function that creates a stream
that produces an event after a given ammount of milliseconds. By default
[`later`][later] is used as a scheduler.
```js
import fromIterable from "@basic-streams/from-iterable"
import later from "@basic-streams/later"
//
// simplest case
fromIterable([1, 2, 3])(x => {

@@ -37,6 +26,12 @@ console.log(x)

// > 3
```
//
// with an interval
fromIterable([1, 2, 3], 10)(x => {
If an `interval` is provided the items will be spread in time by that ammount of
milliseconds, with the first one delayed. If the interval is `0` the items will
be produced as soon as possible but still asynchronously.
```js
import fromIterable from "@basic-streams/from-iterable"
fromIterable([1, 2, 3], 5000)(x => {
console.log(x)

@@ -49,6 +44,11 @@ })

// _________1_________2_________3
// ____1____2____3
```
//
// with a generator function
Note that iterable is consumed lazily, meaning that `next()` is called only when
value is needed.
```js
import fromIterable from "@basic-streams/from-iterable"
function* generator() {

@@ -60,3 +60,3 @@ const startTime = Date.now()

}
fromIterable(generator(), 10)(x => {
fromIterable(generator(), 5000)(x => {
console.log(x)

@@ -66,14 +66,20 @@ })

// > 0
// > 10
// > 20
// > 5000
// > 10000
// 0 10 20
// _________._________._________.
// 0 5000 10000
// ____.____.____.
```
//
// with a custom scheduler
You can provide a custom `scheduler`, a function that creates a stream producing
an event after a given time. By default [`later`][later] is used as a scheduler.
```js
import fromIterable from "@basic-streams/from-iterable"
import later from "@basic-streams/later"
function scheduler(time) {
return later(time / 2)
}
fromIterable([1, 2, 3], 10, scheduler)(x => {
fromIterable([1, 2, 3], 6000, scheduler)(x => {
console.log(x)

@@ -86,3 +92,3 @@ })

// ____1____2____3
// __1__2__3
```

@@ -89,0 +95,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc