Rxjs do something on first emit from multiple subscriptions

Discussão em 'Angular' iniciado por Emeric, Fevereiro 26, 2025.

  1. Emeric

    Emeric Guest

    Is there a clean way to do something on first emit from multiple subscriptions ?

    e.g.:

    this.subscription1 = this.service.getData1().subscribe(data => {
    this.data1 = data;
    console.log('1');
    });

    this.subscription2 = this.service.getData2().subscribe(data => {
    this.data2 = data2;
    console.log('2');
    });

    // Do something after first emit from subscription1 AND subscription2
    doSomething();

    ...

    doSomething() {
    console.log('Hello world !');
    }


    Output goal:

    1
    2
    Hello world !
    1
    2
    1
    1
    2
    1
    2
    2
    ...

    Continue reading...

Compartilhe esta Página