Socket
Socket
Sign inDemoInstall

@effection/channel

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/channel - npm Package Compare versions

Comparing version 2.0.0-side-effects.1628189696867 to 2.0.0-v2-writable-unification.1633595877341

82

CHANGELOG.md
# Changelog
## \[2.0.0-beta.20]
- Fix a bug when using blockParent where the children are not getting halt on an explicit halt.
- Bumped due to a bump in @effection/core.
- [1cd9803](https://github.com/thefrontside/effection/commit/1cd98033d2641989114f9589c7d887954fa66781) Fix halting children for blockParent tasks on 2021-09-30
## \[2.0.0-beta.19]
- Add Stream `toBuffer` and Stream `buffered` so we have both options on either accessing the buffer directly or returning the stream.
- Bumped due to a bump in @effection/stream.
- [fe60532](https://github.com/thefrontside/effection/commit/fe60532c3f8cfdd8b53c324b7ea8e38e437f080f) Add both toBuffer and buffered to Stream on 2021-09-30
## \[2.0.0-beta.18]
- Stream `buffer` returns the actual buffer and gives direct access to it
- Bumped due to a bump in @effection/stream.
- [07c8f83](https://github.com/thefrontside/effection/commit/07c8f83b5968f347ca72795c447be411e66274ed) Stream `buffer` returns the actual buffer on 2021-09-30
## \[2.0.0-beta.17]
- - [0248d79](https://github.com/thefrontside/effection/commit/0248d79a33dcfc4200b0832aba975c9cad08981e) Add package readmes on 2021-09-28
- Split off `Stream` from subscription package into its own `@effection/stream` package
- [248de1d](https://github.com/thefrontside/effection/commit/248de1dd31d172762d9601a2b5acd983dce61ab0) Split `Stream` into its own package on 2021-09-27
## \[2.0.0-beta.16]
- Adjust the propagation of errors for resources to make it possible to catch errors from `init`
- Bumped due to a bump in @effection/core.
- [75a7248](https://github.com/thefrontside/effection/commit/75a7248ae13d1126bbcaf9b6223f348168e987d0) Catch errors thrown during resource init on 2021-09-21
- Enable support for resources in higher order operations `all`, `race` and `withTimeout`.
- Bumped due to a bump in @effection/core.
- [bbe6cdc](https://github.com/thefrontside/effection/commit/bbe6cdc44184a7669278d0d01ad23a2a79a69e52) Enable resource support for higher order operations on 2021-09-09
## \[2.0.0-beta.15]
- Add shortcuts to create resolved/rejected/halted futures via Future.resolve(123), etc...
- Bumped due to a bump in @effection/core.
- [9599dde](https://github.com/thefrontside/effection/commit/9599dde14e9bc3ba4ac7ea473e8624164727be0c) Add shortcuts for resolves/rejected/halted future on 2021-09-08
## \[2.0.0-beta.14]
- Add @effection/fetch as a dependency and reexport it
- Bumped due to a bump in @effection/core.
- [5ab5d06](https://github.com/thefrontside/effection/commit/5ab5d0691af75f3583de97402b5aac12325e2918) Reexport @effection/fetch from effection package on 2021-08-26
- Share internal run loop among task, task future and task controller. Prevents race conditions which cause internal errors.
- Bumped due to a bump in @effection/core.
- [222d511](https://github.com/thefrontside/effection/commit/222d5116c388c5b597cc3ec5e0fb64b4d22b273a) Share event loop among controller, task and future on 2021-09-01
- Introduce task scope as an alternative to resources for being able to access the outer scope of an operation
- Bumped due to a bump in @effection/core.
- [3ed11bd](https://github.com/thefrontside/effection/commit/3ed11bd4f5d980cd130ea894a63acb57450c5aac) Make resource task accessible through init task on 2021-08-27
- Add `toString()` method to task for nicely formatted rendering of task structure
- Bumped due to a bump in @effection/core.
- [9a63928](https://github.com/thefrontside/effection/commit/9a6392836704ad527d6da5195f5736462d69bef8) Add toString output for tasks on 2021-08-31
## \[2.0.0-beta.13]
- Allow channels to be named so their internal stream gets named
- [c52018a](https://github.com/thefrontside/effection/commit/c52018a1035d551cef76a757d1dc29781b59c851) Allow channels to be named on 2021-08-27
## \[2.0.0-beta.12]
- Update core dependency
- Bumped due to a bump in @effection/mocha.
- [d92eee5](https://github.com/thefrontside/effection/commit/d92eee594fdb8dc6d8ab6a37b6aa362122e63f6e) Update core dependency on 2021-08-16
## \[2.0.0-beta.11]
- Use Object.create to wrap error objects rather than copying properties
- Bumped due to a bump in @effection/core.
- [a56ae2a](https://github.com/thefrontside/effection/commit/a56ae2af8a6247697b8b6253bd35b6d9e569613d) Use Object.create to create error object with trace on 2021-08-16
## \[2.0.0-beta.10]
- add `Task#spawn` operation to spawn new task with a specific scope
- Bumped due to a bump in @effection/core.
- [a71d65b](https://github.com/thefrontside/effection/commit/a71d65b77df5c337a78b7934edd181080eacf5bf) Add changefile on 2021-07-27
## \[2.0.0-beta.9]
- Add sideEffects field to package.json
- [383141d](https://github.com/thefrontside/effection/commit/383141dc556c6a781d98087f3b68085d5eb31173) Add sideEffects field to package.json ([#470](https://github.com/thefrontside/effection/pull/470)) on 2021-08-05
## \[2.0.0-beta.8]

@@ -4,0 +86,0 @@

9

dist-cjs/channel.d.ts

@@ -1,9 +0,8 @@

import { WritableStream, Writable, Stream } from '@effection/subscription';
export declare type Close<T> = (...args: T extends undefined ? [] : [T]) => void;
export declare type Send<T> = Writable<T>['send'];
import { Sink } from '@effection/subscription';
import { Stream } from '@effection/stream';
export declare type ChannelOptions = {
maxSubscribers?: number;
name?: string;
};
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> {
close: Close<TClose>;
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> {
stream: Stream<T, TClose>;

@@ -10,0 +9,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createChannel = void 0;
const subscription_1 = require("@effection/subscription");
const stream_1 = require("@effection/stream");
const events_1 = require("@effection/events");

@@ -15,3 +15,3 @@ const events_2 = require("events");

}
let stream = subscription_1.createStream((publish) => function* (task) {
let stream = stream_1.createStream((publish) => function* (task) {
let subscription = events_1.on(bus, 'event').subscribe(task);

@@ -24,11 +24,11 @@ while (true) {

else {
publish(next.value);
yield publish(next.value);
}
}
});
let send = (message) => {
}, options.name);
let send = function* (message) {
bus.emit('event', { done: false, value: message });
};
let close = (...args) => {
bus.emit('event', { done: true, value: args[0] });
let close = function* (value) {
bus.emit('event', { done: true, value });
};

@@ -35,0 +35,0 @@ return { send, close, stream, ...stream };

@@ -1,9 +0,8 @@

import { WritableStream, Writable, Stream } from '@effection/subscription';
export declare type Close<T> = (...args: T extends undefined ? [] : [T]) => void;
export declare type Send<T> = Writable<T>['send'];
import { Sink } from '@effection/subscription';
import { Stream } from '@effection/stream';
export declare type ChannelOptions = {
maxSubscribers?: number;
name?: string;
};
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> {
close: Close<TClose>;
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> {
stream: Stream<T, TClose>;

@@ -10,0 +9,0 @@ }

@@ -1,2 +0,2 @@

import { createStream } from '@effection/subscription';
import { createStream } from '@effection/stream';
import { on } from '@effection/events';

@@ -20,11 +20,11 @@ import { EventEmitter } from 'events';

else {
publish(next.value);
yield publish(next.value);
}
}
});
let send = (message) => {
}, options.name);
let send = function* (message) {
bus.emit('event', { done: false, value: message });
};
let close = (...args) => {
bus.emit('event', { done: true, value: args[0] });
let close = function* (value) {
bus.emit('event', { done: true, value });
};

@@ -31,0 +31,0 @@ return { send, close, stream, ...stream };

{
"name": "@effection/channel",
"version": "2.0.0-side-effects.1628189696867",
"version": "2.0.0-v2-writable-unification.1633595877341",
"description": "MPMC Channel implementation for effection",

@@ -10,3 +10,3 @@ "main": "dist-cjs/index.js",

"sideEffects": false,
"homepage": "https://github.com/thefrontside/effection",
"homepage": "https://frontside.com/effection",
"repository": {

@@ -32,3 +32,2 @@ "type": "git",

"devDependencies": {
"@effection/mocha": "2.0.0-side-effects.1628189696867",
"@frontside/tsconfig": "^1.2.0",

@@ -45,6 +44,6 @@ "@types/node": "^16.3.2",

"dependencies": {
"@effection/core": "2.0.0-side-effects.1628189696867",
"@effection/events": "2.0.0-side-effects.1628189696867",
"@effection/subscription": "2.0.0-side-effects.1628189696867"
"@effection/core": "2.0.0-v2-writable-unification.1633595877341",
"@effection/events": "2.0.0-v2-writable-unification.1633595877341",
"@effection/stream": "2.0.0-v2-writable-unification.1633595877341"
}
}
# @effection/channel
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Created by Frontside](https://img.shields.io/badge/created%20by-frontside-26abe8.svg)](https://frontside.com)
[![Chat on Discord](https://img.shields.io/discord/700803887132704931?Label=Discord)](https://discord.gg/Ug5nWH8a)
A multi producer, multi consumer unbounded channel for Effection. Channels are
useful for communicating between different parts of a system, for building
pubsub buses, or a whole lot of other synchronization needs.
[Effection][] is the structured concurrency toolkit for JavaScript. You can find
detailed information about channels, streams and subscriptions at [https://frontside.com/effection/docs/guides/collections#stream](https://frontside.com/effection/docs/guides/collections#stream)
Sending to a channel is synchronous and does not require the sender to be
running in an effection context. However, reading from a channel can only be
done through operations.
Because of the synchronous nature of sends, channels are unbounded in size, which
means that they cannot handle backpressure. As such, channels should be used more
as a synchronization mechanism, rather than a high-throughput system.
## Usage
A basic example:
``` typescript
import { createChannel } from '@effection/channel';
import { main } from '@effection/main';
import { sleep } from '@effection/core';
main(function*() {
let channel = createChannel();
spawn(function*() {
while(true) {
yield sleep(1000);
channel.send({ message: "ping" });
}
});
let subscription = yield channel.subscribe();
while(true) {
let { value } = yield subscription.next();
console.log("value:", value);
}
});
[Effection]: https://frontside.com/effection

@@ -1,15 +0,12 @@

import { createStream, WritableStream, Writable, Stream } from '@effection/subscription';
import { Sink, Close } from '@effection/subscription';
import { createStream, Stream } from '@effection/stream';
import { on } from '@effection/events';
import { EventEmitter } from 'events';
export type Close<T> = (...args: T extends undefined ? [] : [T]) => void;
export type Send<T> = Writable<T>['send'];
export type ChannelOptions = {
maxSubscribers?: number;
name?: string;
}
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> {
close: Close<TClose>;
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> {
stream: Stream<T, TClose>;

@@ -34,16 +31,16 @@ }

} else {
publish(next.value);
yield publish(next.value);
}
}
});
}, options.name);
let send: Send<T> = (message: T) => {
let send = function*(message: T) {
bus.emit('event', { done: false, value: message });
};
let close: Close<TClose> = (...args) => {
bus.emit('event', { done: true, value: args[0] });
};
let close = function*(value: TClose) {
bus.emit('event', { done: true, value });
} as Close<TClose>;
return { send, close, stream , ...stream };
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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