Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Implementing custom subscribers

Pragya Keshap answered on February 19, 2023 Popularity 2/10 Helpfulness 1/10

Contents


More Related Answers

  • Types of subscribers

  • Implementing custom subscribers

    0

    n our custom Subscriber implementation, we do the following:

    Our subscriber has to hold a reference to a Subscription that binds a Publisher and our Subscriber. As subscription and data processing may happen in different threads, we use the volatile keyword to make sure that all threads will have the correct reference to the Subscription instance.

    When a subscription arrives, our Subscriber is informed with the onSubscribe callback. Here, we save the subscription (2.1) and request the initial demand (2.2). Without that request, a TCK complaint provider will not be allowed to send data and elements processing will not start at all.

    In the onNext callback, we log the received data and request the next element. In this case, we use a straightforward pull model (subscription.request(1)) for backpressure management.

    Here, we generate a simple stream with the just factory method.

    Here, we subscribe our custom subscriber to the Reactive Stream defined in step

    Popularity 2/10 Helpfulness 1/10 Language java
    Source: Grepper
    Tags: java
    Link to this answer
    Share Copy Link
    Contributed on Feb 19 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.