Socket
Socket
Sign inDemoInstall

@effection/events

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/events - npm Package Compare versions

Comparing version 2.0.0-v2-writable-unification.1633595877341 to 2.0.0

11

CHANGELOG.md
# 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 @@

/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* An object which is able to emit events, and provides methods to subsribe and
* unsubscribe to these events. Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*/
export declare type EventSource = EventEmitterSource | EventTargetSource;

@@ -4,0 +12,0 @@ export declare function addListener<TArgs extends unknown[] = [unknown]>(source: EventSource, name: string, listener: (...args: TArgs) => void): void;

25

dist-cjs/on.d.ts
import { Stream } from '@effection/stream';
import { EventSource } from './event-source';
/**
* Creates a {@link Stream} from an event source and event name that
* Creates a `Stream` from an event source and event name that
* produces the event as its next value every time that the source
* raises it. Streams created in this way are infinite.
*
* Both {@link EventTarget} and {@link EventEmitter}
* are supported.
* Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*

@@ -30,2 +33,8 @@ * ### Example

* }));
* ```
*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam T the type of the argument to the emitted event
*/

@@ -35,6 +44,6 @@ export declare function on<T = unknown>(source: EventSource, name: string, streamName?: string): Stream<T, void>;

* Exactly like {@link on | on()} except each value produced by the
* stream is an {@link Array} of all the arguments passed when the event was
* stream is an array of all the arguments passed when the event was
* dispatched.
*
* This should rarely be needed, and never with {@link EventTarget}s
* This should rarely be needed, and never with `EventTarget`
* which always invoke their event listeners with a single argument.

@@ -60,4 +69,8 @@ *

*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export declare function onEmit<T extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName?: string): Stream<T, void>;
export declare function onEmit<TArgs extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName?: string): Stream<TArgs, void>;
//# sourceMappingURL=on.d.ts.map

@@ -8,8 +8,11 @@ "use strict";

/**
* Creates a {@link Stream} from an event source and event name that
* Creates a `Stream` from an event source and event name that
* produces the event as its next value every time that the source
* raises it. Streams created in this way are infinite.
*
* Both {@link EventTarget} and {@link EventEmitter}
* are supported.
* Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*

@@ -35,7 +38,12 @@ * ### Example

* }));
* ```
*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam T the type of the argument to the emitted event
*/
function on(source, name, streamName = `on('${name}')`) {
return stream_1.createStream((publish) => core_1.withLabels(function* (task) {
let listener = (value) => task.run(publish(value));
event_source_1.addListener(source, name, listener);
return stream_1.createStream((publish) => core_1.withLabels(function* () {
event_source_1.addListener(source, name, publish);
try {

@@ -45,3 +53,3 @@ yield;

finally {
event_source_1.removeListener(source, name, listener);
event_source_1.removeListener(source, name, publish);
}

@@ -53,6 +61,6 @@ }, { name: 'listen', eventName: name, source: source.toString() }), streamName);

* Exactly like {@link on | on()} except each value produced by the
* stream is an {@link Array} of all the arguments passed when the event was
* stream is an array of all the arguments passed when the event was
* dispatched.
*
* This should rarely be needed, and never with {@link EventTarget}s
* This should rarely be needed, and never with `EventTarget`
* which always invoke their event listeners with a single argument.

@@ -78,6 +86,10 @@ *

*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
function onEmit(source, name, streamName = `onEmit('${name}')`) {
return stream_1.createStream((publish) => core_1.withLabels(function* (task) {
let listener = (...args) => task.run(publish(args));
return stream_1.createStream((publish) => core_1.withLabels(function* () {
let listener = (...args) => publish(args);
event_source_1.addListener(source, name, listener);

@@ -84,0 +96,0 @@ try {

@@ -24,2 +24,6 @@ import { Operation } from '@effection/core';

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam T the type of the argument to the emitted event
*/

@@ -29,7 +33,7 @@ export declare function once<T = unknown>(source: EventSource, eventName: string): Operation<T>;

* Exactly like {@link once | once()} except the value produced is an
* {@link Array} of all the arguments passed when the event was
* array of all the arguments passed when the event was
* dispatched.
*
* In very rare cases, some event emitters pass multiple arguments to
* their event handlers. For example the {@link ChildProcess} in
* their event handlers. For example the [ChildProcess](https://nodejs.org/api/child_process.html) in
* NodeJS emits both a status code _and_ a signal to the 'exit'

@@ -41,5 +45,5 @@ * event. It would not be possible to read the signal from the `exit`

*
* While it is supported, you should never need to use `onceEmit()` on
* an {@link EventTarget} since only a single argument is ever passed
* to its event handler. In those cases, always use {@link once | once()}
* While it is supported, you should never need to use `onceEmit()` on an
* `EventTarget` since only a single argument is ever passed to its event
* handler. In those cases, always use {@link once | once()}
*

@@ -51,4 +55,8 @@ * ### Example

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export declare function onceEmit<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs>;
//# sourceMappingURL=once.d.ts.map

@@ -27,2 +27,6 @@ "use strict";

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam T the type of the argument to the emitted event
*/

@@ -41,7 +45,7 @@ function once(source, eventName) {

* Exactly like {@link once | once()} except the value produced is an
* {@link Array} of all the arguments passed when the event was
* array of all the arguments passed when the event was
* dispatched.
*
* In very rare cases, some event emitters pass multiple arguments to
* their event handlers. For example the {@link ChildProcess} in
* their event handlers. For example the [ChildProcess](https://nodejs.org/api/child_process.html) in
* NodeJS emits both a status code _and_ a signal to the 'exit'

@@ -53,5 +57,5 @@ * event. It would not be possible to read the signal from the `exit`

*
* While it is supported, you should never need to use `onceEmit()` on
* an {@link EventTarget} since only a single argument is ever passed
* to its event handler. In those cases, always use {@link once | once()}
* While it is supported, you should never need to use `onceEmit()` on an
* `EventTarget` since only a single argument is ever passed to its event
* handler. In those cases, always use {@link once | once()}
*

@@ -63,2 +67,6 @@ * ### Example

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam TArgs the type of the array of arguments to the emitted event
*/

@@ -65,0 +73,0 @@ function onceEmit(source, eventName) {

import { Operation } from '@effection/core';
import { EventSource } from './event-source';
/**
* Subscribe to the `error` event and throw the emitted error.
*
* In evented code, errors are often emitted as an event named `error`.
* Within Effection, we want to take this emitted error and throw it, so that
* upstream code can handle the failure in some sensible way. While this is
* simple to implement, it is such a common pattern that we have provided this
* helper function to simplify this type of code.
*
* ### Example
*
* A WebSocket can emit an error event when the connection fails:
*
* ```javascript
* let socket = new WebSocket(url);
* yield throwOnErrorEvent(socket);
* yield on(socket, 'message').forEach((message) => { ... });
* ```
*
* @param source an object which emits error events
*/
export declare function throwOnErrorEvent(source: EventSource): Operation<void>;
//# sourceMappingURL=throw-on-error-event.d.ts.map

@@ -5,2 +5,23 @@ "use strict";

const once_1 = require("./once");
/**
* Subscribe to the `error` event and throw the emitted error.
*
* In evented code, errors are often emitted as an event named `error`.
* Within Effection, we want to take this emitted error and throw it, so that
* upstream code can handle the failure in some sensible way. While this is
* simple to implement, it is such a common pattern that we have provided this
* helper function to simplify this type of code.
*
* ### Example
*
* A WebSocket can emit an error event when the connection fails:
*
* ```javascript
* let socket = new WebSocket(url);
* yield throwOnErrorEvent(socket);
* yield on(socket, 'message').forEach((message) => { ... });
* ```
*
* @param source an object which emits error events
*/
function* throwOnErrorEvent(source) {

@@ -7,0 +28,0 @@ let error = yield once_1.once(source, 'error');

/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* An object which is able to emit events, and provides methods to subsribe and
* unsubscribe to these events. Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*/
export declare type EventSource = EventEmitterSource | EventTargetSource;

@@ -4,0 +12,0 @@ export declare function addListener<TArgs extends unknown[] = [unknown]>(source: EventSource, name: string, listener: (...args: TArgs) => void): void;

import { Stream } from '@effection/stream';
import { EventSource } from './event-source';
/**
* Creates a {@link Stream} from an event source and event name that
* Creates a `Stream` from an event source and event name that
* produces the event as its next value every time that the source
* raises it. Streams created in this way are infinite.
*
* Both {@link EventTarget} and {@link EventEmitter}
* are supported.
* Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*

@@ -30,2 +33,8 @@ * ### Example

* }));
* ```
*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam T the type of the argument to the emitted event
*/

@@ -35,6 +44,6 @@ export declare function on<T = unknown>(source: EventSource, name: string, streamName?: string): Stream<T, void>;

* Exactly like {@link on | on()} except each value produced by the
* stream is an {@link Array} of all the arguments passed when the event was
* stream is an array of all the arguments passed when the event was
* dispatched.
*
* This should rarely be needed, and never with {@link EventTarget}s
* This should rarely be needed, and never with `EventTarget`
* which always invoke their event listeners with a single argument.

@@ -60,4 +69,8 @@ *

*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export declare function onEmit<T extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName?: string): Stream<T, void>;
export declare function onEmit<TArgs extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName?: string): Stream<TArgs, void>;
//# sourceMappingURL=on.d.ts.map

@@ -5,8 +5,11 @@ import { withLabels } from '@effection/core';

/**
* Creates a {@link Stream} from an event source and event name that
* Creates a `Stream` from an event source and event name that
* produces the event as its next value every time that the source
* raises it. Streams created in this way are infinite.
*
* Both {@link EventTarget} and {@link EventEmitter}
* are supported.
* Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*

@@ -32,7 +35,12 @@ * ### Example

* }));
* ```
*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam T the type of the argument to the emitted event
*/
export function on(source, name, streamName = `on('${name}')`) {
return createStream((publish) => withLabels(function* (task) {
let listener = (value) => task.run(publish(value));
addListener(source, name, listener);
return createStream((publish) => withLabels(function* () {
addListener(source, name, publish);
try {

@@ -42,3 +50,3 @@ yield;

finally {
removeListener(source, name, listener);
removeListener(source, name, publish);
}

@@ -49,6 +57,6 @@ }, { name: 'listen', eventName: name, source: source.toString() }), streamName);

* Exactly like {@link on | on()} except each value produced by the
* stream is an {@link Array} of all the arguments passed when the event was
* stream is an array of all the arguments passed when the event was
* dispatched.
*
* This should rarely be needed, and never with {@link EventTarget}s
* This should rarely be needed, and never with `EventTarget`
* which always invoke their event listeners with a single argument.

@@ -74,6 +82,10 @@ *

*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export function onEmit(source, name, streamName = `onEmit('${name}')`) {
return createStream((publish) => withLabels(function* (task) {
let listener = (...args) => task.run(publish(args));
return createStream((publish) => withLabels(function* () {
let listener = (...args) => publish(args);
addListener(source, name, listener);

@@ -80,0 +92,0 @@ try {

@@ -24,2 +24,6 @@ import { Operation } from '@effection/core';

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam T the type of the argument to the emitted event
*/

@@ -29,7 +33,7 @@ export declare function once<T = unknown>(source: EventSource, eventName: string): Operation<T>;

* Exactly like {@link once | once()} except the value produced is an
* {@link Array} of all the arguments passed when the event was
* array of all the arguments passed when the event was
* dispatched.
*
* In very rare cases, some event emitters pass multiple arguments to
* their event handlers. For example the {@link ChildProcess} in
* their event handlers. For example the [ChildProcess](https://nodejs.org/api/child_process.html) in
* NodeJS emits both a status code _and_ a signal to the 'exit'

@@ -41,5 +45,5 @@ * event. It would not be possible to read the signal from the `exit`

*
* While it is supported, you should never need to use `onceEmit()` on
* an {@link EventTarget} since only a single argument is ever passed
* to its event handler. In those cases, always use {@link once | once()}
* While it is supported, you should never need to use `onceEmit()` on an
* `EventTarget` since only a single argument is ever passed to its event
* handler. In those cases, always use {@link once | once()}
*

@@ -51,4 +55,8 @@ * ### Example

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export declare function onceEmit<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs>;
//# sourceMappingURL=once.d.ts.map

@@ -24,2 +24,6 @@ import { createFuture, withLabels } from '@effection/core';

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam T the type of the argument to the emitted event
*/

@@ -37,7 +41,7 @@ export function once(source, eventName) {

* Exactly like {@link once | once()} except the value produced is an
* {@link Array} of all the arguments passed when the event was
* array of all the arguments passed when the event was
* dispatched.
*
* In very rare cases, some event emitters pass multiple arguments to
* their event handlers. For example the {@link ChildProcess} in
* their event handlers. For example the [ChildProcess](https://nodejs.org/api/child_process.html) in
* NodeJS emits both a status code _and_ a signal to the 'exit'

@@ -49,5 +53,5 @@ * event. It would not be possible to read the signal from the `exit`

*
* While it is supported, you should never need to use `onceEmit()` on
* an {@link EventTarget} since only a single argument is ever passed
* to its event handler. In those cases, always use {@link once | once()}
* While it is supported, you should never need to use `onceEmit()` on an
* `EventTarget` since only a single argument is ever passed to its event
* handler. In those cases, always use {@link once | once()}
*

@@ -59,2 +63,6 @@ * ### Example

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam TArgs the type of the array of arguments to the emitted event
*/

@@ -61,0 +69,0 @@ export function onceEmit(source, eventName) {

import { Operation } from '@effection/core';
import { EventSource } from './event-source';
/**
* Subscribe to the `error` event and throw the emitted error.
*
* In evented code, errors are often emitted as an event named `error`.
* Within Effection, we want to take this emitted error and throw it, so that
* upstream code can handle the failure in some sensible way. While this is
* simple to implement, it is such a common pattern that we have provided this
* helper function to simplify this type of code.
*
* ### Example
*
* A WebSocket can emit an error event when the connection fails:
*
* ```javascript
* let socket = new WebSocket(url);
* yield throwOnErrorEvent(socket);
* yield on(socket, 'message').forEach((message) => { ... });
* ```
*
* @param source an object which emits error events
*/
export declare function throwOnErrorEvent(source: EventSource): Operation<void>;
//# sourceMappingURL=throw-on-error-event.d.ts.map
import { once } from './once';
/**
* Subscribe to the `error` event and throw the emitted error.
*
* In evented code, errors are often emitted as an event named `error`.
* Within Effection, we want to take this emitted error and throw it, so that
* upstream code can handle the failure in some sensible way. While this is
* simple to implement, it is such a common pattern that we have provided this
* helper function to simplify this type of code.
*
* ### Example
*
* A WebSocket can emit an error event when the connection fails:
*
* ```javascript
* let socket = new WebSocket(url);
* yield throwOnErrorEvent(socket);
* yield on(socket, 'message').forEach((message) => { ... });
* ```
*
* @param source an object which emits error events
*/
export function* throwOnErrorEvent(source) {

@@ -3,0 +24,0 @@ let error = yield once(source, 'error');

{
"name": "@effection/events",
"version": "2.0.0-v2-writable-unification.1633595877341",
"version": "2.0.0",
"description": "Helpers for listening to events with effection",

@@ -31,4 +31,4 @@ "main": "dist-cjs/index.js",

"dependencies": {
"@effection/core": "2.0.0-v2-writable-unification.1633595877341",
"@effection/stream": "2.0.0-v2-writable-unification.1633595877341"
"@effection/core": "2.0.0",
"@effection/stream": "2.0.0"
},

@@ -35,0 +35,0 @@ "devDependencies": {

import { EventEmitter } from 'events';
/**
* An object which is able to emit events, and provides methods to subsribe and
* unsubscribe to these events. Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*/
export type EventSource = EventEmitterSource | EventTargetSource

@@ -4,0 +12,0 @@

@@ -7,8 +7,11 @@ import { withLabels } from '@effection/core';

/**
* Creates a {@link Stream} from an event source and event name that
* Creates a `Stream` from an event source and event name that
* produces the event as its next value every time that the source
* raises it. Streams created in this way are infinite.
*
* Both {@link EventTarget} and {@link EventEmitter}
* are supported.
* Both
* [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
* from the browser DOM and
* [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
* from node are supported.
*

@@ -34,11 +37,16 @@ * ### Example

* }));
* ```
*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam T the type of the argument to the emitted event
*/
export function on<T = unknown>(source: EventSource, name: string, streamName = `on('${name}')`): Stream<T, void> {
return createStream((publish) => withLabels(function*(task) {
let listener = (value: T) => task.run(publish(value));
addListener(source, name, listener);
return createStream((publish) => withLabels(function*() {
addListener(source, name, publish);
try {
yield;
} finally {
removeListener(source, name, listener);
removeListener(source, name, publish);
}

@@ -50,6 +58,6 @@ }, { name: 'listen', eventName: name, source: source.toString() }), streamName);

* Exactly like {@link on | on()} except each value produced by the
* stream is an {@link Array} of all the arguments passed when the event was
* stream is an array of all the arguments passed when the event was
* dispatched.
*
* This should rarely be needed, and never with {@link EventTarget}s
* This should rarely be needed, and never with `EventTarget`
* which always invoke their event listeners with a single argument.

@@ -75,6 +83,10 @@ *

*
* @param source an object which emits events
* @param name the name of the event to subscribe to
* @param streamName the name of the returned stream, useful for debugging
* @typeParam TArgs the type of the array of arguments to the emitted event
*/
export function onEmit<T extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName = `onEmit('${name}')`): Stream<T, void> {
return createStream((publish) => withLabels(function*(task) {
let listener = (...args: T) => task.run(publish(args));
export function onEmit<TArgs extends Array<unknown> = unknown[]>(source: EventSource, name: string, streamName = `onEmit('${name}')`): Stream<TArgs, void> {
return createStream((publish) => withLabels(function*() {
let listener = (...args: TArgs) => publish(args);
addListener(source, name, listener);

@@ -81,0 +93,0 @@ try {

import { Operation, createFuture, withLabels } from '@effection/core';
import { EventSource, addListener, removeListener } from './event-source';
/**

@@ -26,2 +25,6 @@ * Takes an event source and event name and returns an

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam T the type of the argument to the emitted event
*/

@@ -40,7 +43,7 @@ export function once<T = unknown>(source: EventSource, eventName: string): Operation<T> {

* Exactly like {@link once | once()} except the value produced is an
* {@link Array} of all the arguments passed when the event was
* array of all the arguments passed when the event was
* dispatched.
*
* In very rare cases, some event emitters pass multiple arguments to
* their event handlers. For example the {@link ChildProcess} in
* their event handlers. For example the [ChildProcess](https://nodejs.org/api/child_process.html) in
* NodeJS emits both a status code _and_ a signal to the 'exit'

@@ -52,5 +55,5 @@ * event. It would not be possible to read the signal from the `exit`

*
* While it is supported, you should never need to use `onceEmit()` on
* an {@link EventTarget} since only a single argument is ever passed
* to its event handler. In those cases, always use {@link once | once()}
* While it is supported, you should never need to use `onceEmit()` on an
* `EventTarget` since only a single argument is ever passed to its event
* handler. In those cases, always use {@link once | once()}
*

@@ -62,2 +65,6 @@ * ### Example

* ```
*
* @param source an object which emits events
* @param eventName the name of the event to subscribe to
* @typeParam TArgs the type of the array of arguments to the emitted event
*/

@@ -64,0 +71,0 @@ export function onceEmit<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs> {

@@ -5,2 +5,23 @@ import { Operation } from '@effection/core';

/**
* Subscribe to the `error` event and throw the emitted error.
*
* In evented code, errors are often emitted as an event named `error`.
* Within Effection, we want to take this emitted error and throw it, so that
* upstream code can handle the failure in some sensible way. While this is
* simple to implement, it is such a common pattern that we have provided this
* helper function to simplify this type of code.
*
* ### Example
*
* A WebSocket can emit an error event when the connection fails:
*
* ```javascript
* let socket = new WebSocket(url);
* yield throwOnErrorEvent(socket);
* yield on(socket, 'message').forEach((message) => { ... });
* ```
*
* @param source an object which emits error events
*/
export function *throwOnErrorEvent(source: EventSource): Operation<void> {

@@ -7,0 +28,0 @@ let error: Error = yield once(source, 'error');

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

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

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

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