AsyncSignalGroup Class
Represents an asynchronous group that manages the lifecycle of an asynchronous action, including emitters for launching the action, handling its success, dealing with failures, and maintaining the signal state of the asynchronous action.
The signal state can be used in Angular’s effect
or computed
functions and in other places
where you would normally use a signal.
The AsyncSignalGroup
class extends AbstractAsyncGroup
and is designed to facilitate
the management of asynchronous actions. This structure allows for organized
and efficient management of complex asynchronous dataflow
@template L
The type representing the data for the launch emitter
@template S
The type representing the data for the success emitter
@template F
The type representing the error data for the fail emitter
API
class AsyncSignalGroup<L, S, F> extends AbstractAsyncGroup<L, S, F> {
readonly launch: Emitter<L>;
readonly success: Emitter<S>;
readonly fail: Emitter<F>;
readonly finish: Emitter<void>;
readonly state: SignalStateType<AsyncData>;
constructor(fallbackValue?: S);
initialize(): this;
complete(): void;
useCache(secOrFn: number | (() => boolean), cacheSize = 10): this;
}
Example
import {asyncSignalGroup} from '@bitfiber/ng/rx';
// Creates an asynchronous group
const group = asyncSignalGroup<number, string[], Error>(({launch}) => {
// Sets an effect to be triggered on new launch emissions
launch.tap(v => console.log(v));
});
// Emits a new value to its own subscribers
group.launch.emit(1);