Giter Site home page Giter Site logo

Comments (3)

mattpodwysocki avatar mattpodwysocki commented on August 18, 2024

RxJava fixed this issue with the mentioned mechanism (queue inside a lock to maintain order, have the first producer drain the concurrency queue outside the lock until it's empty). It's a potentially breaking change though, in that sending a new value may be queued instead of completing inline.

from reactive.

akarnokd avatar akarnokd commented on August 18, 2024

You can do this lock-free. Instead of a plain queue, use a linked-node structure with volatile next pointers. Each subscribing Observer gets a manager Object that picks the current head of the linked structure and walks the nodes until their end; doing it while in a so-called drain-mode. The role of the outer BehaviorSubject.OnNext is to add to the tail of the linked-node structure, move the head pointer one further and notify each active Observer's manager to enter their drain mode. The drawback of this is the constant allocation of nodes for each incoming value - just like the size-bound ReplaySubject does it.

from reactive.

akarnokd avatar akarnokd commented on August 18, 2024

BehaviorSubject uses a lock to capture a snapshot of observers. When an observer subscribes, the subscription and the last cached value is emitted under this lock, thus a concurrent OnNext has to wait for it and no reordering happens.

from reactive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.