Start multiple independent requests that rely on the same emitted value of another observable

Discussão em 'Angular' iniciado por berno, Março 3, 2025.

  1. berno

    berno Guest

    I need to start 3 independent requests in a component that rely on a value emitted by another observable.

    The first request provides an ID, once that ID is emitted I have to start 3 independent asynchronous requests which need that ID to recover the data from server.

    The 3 requests should not be merged together and should remain separate so that I can be able to subscribe to each of those independent requests.

    const source_id = <async_request_ID>;
    const source_A = <async_request_A(ID)>;
    const source_B = <async_request_B(ID)>;
    const source_C = <async_request_C(ID)>;

    source_id.pipe(
    operator_I_am_looking_For((id) => source_A(id), source_B(id), source_C(id))
    )

    source_A.subscribe(...);
    source_B.subscribe(...);
    source_C.subscribe(...);


    Probably the best way to handle this scenario is to notify the emitted value of the first request (the ID) but I'd like to know if exists a way to handle that with some kind of operator.

    Continue reading...

Compartilhe esta Página