Skip to content

merge

Merges the input streams or subjections, returning a new stream.

image

  • Type

    typescript
    type merge: (...args: (Stream | Subjection)[]) => Stream;
  • Details

    • Stream merging operation refers to pushing data to the new stream in time order, as long as any input stream pushes data.
    • The new stream will unsubscribe when all input streams are unsubscribed.
    • The new stream will finish when all input streams have finished.
  • Example

    typescript
    import { $, merge } from "fluth";
    
    const stream1$ = $(1);
    const stream2$ = $("hello");
    const stream3$ = $(true);
    
    const merged$ = merge(stream1$, stream2$, stream3$);
    
    merged$.then((value) => console.log(value));
    console.log(merged$.value);
    // prints: undefined
    
    stream1$.next(2);
    // prints: 2
    stream2$.next("world");
    // prints: world
    stream3$.next(false);
    // prints: false
    stream1$.next(3);
    // prints: 3