StoreReferenceAsyncGroup

AsyncGroup Class

Represents an asynchronous group that manages the lifecycle of an asynchronous action, providing emitters for launching actions, handling success, dealing with failures, and managing the state of these actions.

The AsyncGroup 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 AsyncGroup<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: StateType<AsyncData>;
  constructor(fallbackValue?: S);
  initialize(): this;
  complete(): void;
  useCache(secOrFn: number | (() => boolean), cacheSize = 10): this;
}

Example

import {asyncGroup} from '@bitfiber/rx';
 
// Creates an asynchronous group
const group = asyncGroup<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);