@effection/channel
Advanced tools
Comparing version 2.0.0-v2-writable-unification.1633595877341 to 2.0.0
# Changelog | ||
## \[2.0.0] | ||
- Release Effection 2.0.0 | ||
- [8bd89ad](https://github.com/thefrontside/effection/commit/8bd89ad40e42805ab6da0fd1b7a49beed9769865) Add 2.0 changeset on %as | ||
## \[2.0.0-beta.21] | ||
- Yielding to something which is not an operation no longer throws an internal error, but properly rejects the task. | ||
- Bumped due to a bump in @effection/core. | ||
- [a3ad19a](https://github.com/thefrontside/effection/commit/a3ad19a3177a731fee5cd2389ab898dee7b1788e) Fix yielding non operation bug on 2021-10-07 | ||
## \[2.0.0-beta.20] | ||
@@ -4,0 +15,0 @@ |
@@ -1,11 +0,62 @@ | ||
import { Sink } from '@effection/subscription'; | ||
import { Stream } from '@effection/stream'; | ||
import { WritableStream, Writable, Stream } from '@effection/stream'; | ||
/** | ||
* @hidden | ||
*/ | ||
export declare type Close<T> = (...args: T extends undefined ? [] : [T]) => void; | ||
/** | ||
* @hidden | ||
*/ | ||
export declare type Send<T> = Writable<T>['send']; | ||
/** | ||
* Options which can be provided when creating a {@link Channel} via {@link createChannel}. | ||
*/ | ||
export declare type ChannelOptions = { | ||
/** | ||
* The maximum number of subscribers that the channel should have. When this limit is exceeded | ||
* a warning is printed to the console. | ||
*/ | ||
maxSubscribers?: number; | ||
/** | ||
* The name of the channel. Useful for debugging purposes. | ||
*/ | ||
name?: string; | ||
}; | ||
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> { | ||
/** | ||
* A `Channel` functions as a broadcast channel, so that multiple consumers cann subscribe | ||
* to the same `Stream`, and messages sent to the channel are received by all consumers. The | ||
* channel is not buffered, so if there are no consumers, the message is dropped. | ||
*/ | ||
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> { | ||
close: Close<TClose>; | ||
stream: Stream<T, TClose>; | ||
} | ||
/** | ||
* Create a new {@link Channel}. | ||
* | ||
* See [the guide on Streams and Subscriptions](https://frontside.com/effection/docs/guides/collections) for more details. | ||
* | ||
* ### Example | ||
* | ||
* ``` javascript | ||
* import { main, createChannel } from 'effection'; | ||
* | ||
* main(function*() { | ||
* let channel = createChannel(); | ||
* | ||
* channel.send('too early'); // the channel has no subscribers yet! | ||
* | ||
* let firstSubscription = yield channel.subscribe(); | ||
* let secondSubscription = yield channel.subscribe(); | ||
* | ||
* channel.send('hello'); | ||
* channel.send('world'); | ||
* | ||
* console.log(yield firstSubscription.expect()); // logs 'hello' | ||
* console.log(yield firstSubscription.expect()); // logs 'world' | ||
* console.log(yield secondSubscription.expect()); // logs 'hello' | ||
* console.log(yield secondSubscription.expect()); // logs 'world' | ||
* }); | ||
* ``` | ||
*/ | ||
export declare function createChannel<T, TClose = undefined>(options?: ChannelOptions): Channel<T, TClose>; | ||
//# sourceMappingURL=channel.d.ts.map |
@@ -7,2 +7,30 @@ "use strict"; | ||
const events_2 = require("events"); | ||
/** | ||
* Create a new {@link Channel}. | ||
* | ||
* See [the guide on Streams and Subscriptions](https://frontside.com/effection/docs/guides/collections) for more details. | ||
* | ||
* ### Example | ||
* | ||
* ``` javascript | ||
* import { main, createChannel } from 'effection'; | ||
* | ||
* main(function*() { | ||
* let channel = createChannel(); | ||
* | ||
* channel.send('too early'); // the channel has no subscribers yet! | ||
* | ||
* let firstSubscription = yield channel.subscribe(); | ||
* let secondSubscription = yield channel.subscribe(); | ||
* | ||
* channel.send('hello'); | ||
* channel.send('world'); | ||
* | ||
* console.log(yield firstSubscription.expect()); // logs 'hello' | ||
* console.log(yield firstSubscription.expect()); // logs 'world' | ||
* console.log(yield secondSubscription.expect()); // logs 'hello' | ||
* console.log(yield secondSubscription.expect()); // logs 'world' | ||
* }); | ||
* ``` | ||
*/ | ||
function createChannel(options = {}) { | ||
@@ -24,11 +52,11 @@ let bus = new events_2.EventEmitter(); | ||
else { | ||
yield publish(next.value); | ||
publish(next.value); | ||
} | ||
} | ||
}, options.name); | ||
let send = function* (message) { | ||
let send = (message) => { | ||
bus.emit('event', { done: false, value: message }); | ||
}; | ||
let close = function* (value) { | ||
bus.emit('event', { done: true, value }); | ||
let close = (...args) => { | ||
bus.emit('event', { done: true, value: args[0] }); | ||
}; | ||
@@ -35,0 +63,0 @@ return { send, close, stream, ...stream }; |
@@ -1,11 +0,62 @@ | ||
import { Sink } from '@effection/subscription'; | ||
import { Stream } from '@effection/stream'; | ||
import { WritableStream, Writable, Stream } from '@effection/stream'; | ||
/** | ||
* @hidden | ||
*/ | ||
export declare type Close<T> = (...args: T extends undefined ? [] : [T]) => void; | ||
/** | ||
* @hidden | ||
*/ | ||
export declare type Send<T> = Writable<T>['send']; | ||
/** | ||
* Options which can be provided when creating a {@link Channel} via {@link createChannel}. | ||
*/ | ||
export declare type ChannelOptions = { | ||
/** | ||
* The maximum number of subscribers that the channel should have. When this limit is exceeded | ||
* a warning is printed to the console. | ||
*/ | ||
maxSubscribers?: number; | ||
/** | ||
* The name of the channel. Useful for debugging purposes. | ||
*/ | ||
name?: string; | ||
}; | ||
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> { | ||
/** | ||
* A `Channel` functions as a broadcast channel, so that multiple consumers cann subscribe | ||
* to the same `Stream`, and messages sent to the channel are received by all consumers. The | ||
* channel is not buffered, so if there are no consumers, the message is dropped. | ||
*/ | ||
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> { | ||
close: Close<TClose>; | ||
stream: Stream<T, TClose>; | ||
} | ||
/** | ||
* Create a new {@link Channel}. | ||
* | ||
* See [the guide on Streams and Subscriptions](https://frontside.com/effection/docs/guides/collections) for more details. | ||
* | ||
* ### Example | ||
* | ||
* ``` javascript | ||
* import { main, createChannel } from 'effection'; | ||
* | ||
* main(function*() { | ||
* let channel = createChannel(); | ||
* | ||
* channel.send('too early'); // the channel has no subscribers yet! | ||
* | ||
* let firstSubscription = yield channel.subscribe(); | ||
* let secondSubscription = yield channel.subscribe(); | ||
* | ||
* channel.send('hello'); | ||
* channel.send('world'); | ||
* | ||
* console.log(yield firstSubscription.expect()); // logs 'hello' | ||
* console.log(yield firstSubscription.expect()); // logs 'world' | ||
* console.log(yield secondSubscription.expect()); // logs 'hello' | ||
* console.log(yield secondSubscription.expect()); // logs 'world' | ||
* }); | ||
* ``` | ||
*/ | ||
export declare function createChannel<T, TClose = undefined>(options?: ChannelOptions): Channel<T, TClose>; | ||
//# sourceMappingURL=channel.d.ts.map |
import { createStream } from '@effection/stream'; | ||
import { on } from '@effection/events'; | ||
import { EventEmitter } from 'events'; | ||
/** | ||
* Create a new {@link Channel}. | ||
* | ||
* See [the guide on Streams and Subscriptions](https://frontside.com/effection/docs/guides/collections) for more details. | ||
* | ||
* ### Example | ||
* | ||
* ``` javascript | ||
* import { main, createChannel } from 'effection'; | ||
* | ||
* main(function*() { | ||
* let channel = createChannel(); | ||
* | ||
* channel.send('too early'); // the channel has no subscribers yet! | ||
* | ||
* let firstSubscription = yield channel.subscribe(); | ||
* let secondSubscription = yield channel.subscribe(); | ||
* | ||
* channel.send('hello'); | ||
* channel.send('world'); | ||
* | ||
* console.log(yield firstSubscription.expect()); // logs 'hello' | ||
* console.log(yield firstSubscription.expect()); // logs 'world' | ||
* console.log(yield secondSubscription.expect()); // logs 'hello' | ||
* console.log(yield secondSubscription.expect()); // logs 'world' | ||
* }); | ||
* ``` | ||
*/ | ||
export function createChannel(options = {}) { | ||
@@ -20,11 +48,11 @@ let bus = new EventEmitter(); | ||
else { | ||
yield publish(next.value); | ||
publish(next.value); | ||
} | ||
} | ||
}, options.name); | ||
let send = function* (message) { | ||
let send = (message) => { | ||
bus.emit('event', { done: false, value: message }); | ||
}; | ||
let close = function* (value) { | ||
bus.emit('event', { done: true, value }); | ||
let close = (...args) => { | ||
bus.emit('event', { done: true, value: args[0] }); | ||
}; | ||
@@ -31,0 +59,0 @@ return { send, close, stream, ...stream }; |
{ | ||
"name": "@effection/channel", | ||
"version": "2.0.0-v2-writable-unification.1633595877341", | ||
"version": "2.0.0", | ||
"description": "MPMC Channel implementation for effection", | ||
@@ -42,6 +42,6 @@ "main": "dist-cjs/index.js", | ||
"dependencies": { | ||
"@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/core": "2.0.0", | ||
"@effection/events": "2.0.0", | ||
"@effection/stream": "2.0.0" | ||
} | ||
} |
@@ -1,15 +0,69 @@ | ||
import { Sink, Close } from '@effection/subscription'; | ||
import { createStream, Stream } from '@effection/stream'; | ||
import { createStream, WritableStream, Writable, Stream } from '@effection/stream'; | ||
import { on } from '@effection/events'; | ||
import { EventEmitter } from 'events'; | ||
/** | ||
* @hidden | ||
*/ | ||
export type Close<T> = (...args: T extends undefined ? [] : [T]) => void; | ||
/** | ||
* @hidden | ||
*/ | ||
export type Send<T> = Writable<T>['send']; | ||
/** | ||
* Options which can be provided when creating a {@link Channel} via {@link createChannel}. | ||
*/ | ||
export type ChannelOptions = { | ||
/** | ||
* The maximum number of subscribers that the channel should have. When this limit is exceeded | ||
* a warning is printed to the console. | ||
*/ | ||
maxSubscribers?: number; | ||
/** | ||
* The name of the channel. Useful for debugging purposes. | ||
*/ | ||
name?: string; | ||
} | ||
export interface Channel<T, TClose = undefined> extends Stream<T, TClose>, Sink<T, TClose> { | ||
/** | ||
* A `Channel` functions as a broadcast channel, so that multiple consumers cann subscribe | ||
* to the same `Stream`, and messages sent to the channel are received by all consumers. The | ||
* channel is not buffered, so if there are no consumers, the message is dropped. | ||
*/ | ||
export interface Channel<T, TClose = undefined> extends WritableStream<T, T, TClose> { | ||
close: Close<TClose>; | ||
stream: Stream<T, TClose>; | ||
} | ||
/** | ||
* Create a new {@link Channel}. | ||
* | ||
* See [the guide on Streams and Subscriptions](https://frontside.com/effection/docs/guides/collections) for more details. | ||
* | ||
* ### Example | ||
* | ||
* ``` javascript | ||
* import { main, createChannel } from 'effection'; | ||
* | ||
* main(function*() { | ||
* let channel = createChannel(); | ||
* | ||
* channel.send('too early'); // the channel has no subscribers yet! | ||
* | ||
* let firstSubscription = yield channel.subscribe(); | ||
* let secondSubscription = yield channel.subscribe(); | ||
* | ||
* channel.send('hello'); | ||
* channel.send('world'); | ||
* | ||
* console.log(yield firstSubscription.expect()); // logs 'hello' | ||
* console.log(yield firstSubscription.expect()); // logs 'world' | ||
* console.log(yield secondSubscription.expect()); // logs 'hello' | ||
* console.log(yield secondSubscription.expect()); // logs 'world' | ||
* }); | ||
* ``` | ||
*/ | ||
export function createChannel<T, TClose = undefined>(options: ChannelOptions = {}): Channel<T, TClose> { | ||
@@ -31,3 +85,3 @@ let bus = new EventEmitter(); | ||
} else { | ||
yield publish(next.value); | ||
publish(next.value); | ||
} | ||
@@ -37,11 +91,11 @@ } | ||
let send = function*(message: T) { | ||
let send: Send<T> = (message: T) => { | ||
bus.emit('event', { done: false, value: message }); | ||
}; | ||
let close = function*(value: TClose) { | ||
bus.emit('event', { done: true, value }); | ||
} as Close<TClose>; | ||
let close: Close<TClose> = (...args) => { | ||
bus.emit('event', { done: true, value: args[0] }); | ||
}; | ||
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32620
349
0
1
+ Added@effection/core@2.0.0(transitive)
+ Added@effection/events@2.0.0(transitive)
+ Added@effection/stream@2.0.0(transitive)
+ Added@effection/subscription@2.0.0(transitive)
- Removed@effection/core@2.0.0-v2-writable-unification.1633595877341(transitive)
- Removed@effection/events@2.0.0-v2-writable-unification.1633595877341(transitive)
- Removed@effection/stream@2.0.0-v2-writable-unification.1633595877341(transitive)
- Removed@effection/subscription@2.0.0-v2-writable-unification.1633595877341(transitive)
Updated@effection/core@2.0.0
Updated@effection/events@2.0.0
Updated@effection/stream@2.0.0