Giter Site home page Giter Site logo

Comments (9)

jbrisbin avatar jbrisbin commented on July 23, 2024

This is a bit of a pain point, to be sure. The idea is to provide an easy use of the framework without having to explicitly start the Dispatching components. But we also don't want them always started because we might be operating in an environment where we'll manage that ourselves (multiple classloading scenario comes to mind here). So we want to do both with as little pain as possible and not have to impose a doInReactor style callback where you can only run code without our strict environment.

Ideally, we should be able to run code from Java main and It Just Works.

from reactor.

wilkinsona avatar wilkinsona commented on July 23, 2024

R is involved in this too. It relies on Context's static initializer having run to initialize self. Prior to 678026b R had no dependency on Context so the following test run on its own would fail:

@Test
public void createAReactor() {
    R.create();
}

678026b inadvertently "fixed" this. Rather than creating a new SynchronousDispatcher, it now uses Context's instead. However, there's now a circular dependency between the two:

  • R.class is loaded
  • Its <clinit> calls Context.synchronousDispatcher
  • Context.class is loaded
  • Its <clinit> calls init which instantiates an instance of R and passes it to R.assignR which sets self on R

from reactor.

wilkinsona avatar wilkinsona commented on July 23, 2024

If auto-initialisation is disabled (by setting the reactor.init.auto system property to false), things are really broken:

  • Context will never instantiate R or call R.assignR, rendering R useless.
  • Context's self will never be set making all of its Dispatchers inaccessible

from reactor.

smaldini avatar smaldini commented on July 23, 2024

This is quite critical, we need to fix that. I failed at providing a right solution without sacrificing convenient API :(

from reactor.

jbrisbin avatar jbrisbin commented on July 23, 2024

Can we do lazy initialization and throw an exception if we're not supposed to auto-init based on the system property?

from reactor.

wilkinsona avatar wilkinsona commented on July 23, 2024

I'm going to explore an approach to this along these lines:

  • Global automatically-initialised Context. Can be disabled with a system property.
  • R uses the global Context. If you've disabled it, you can't use R (or we could let people create and set a global Context)
  • Everything else that relies on Context then needs to be able to be given one when it's created, or if it's not given one use the global one. For things like Composable where we might be creating an Observable from another one, it needs to inherit the Context.

from reactor.

jbrisbin avatar jbrisbin commented on July 23, 2024

To add some complications to this task: it's very easy to shoot yourself in the foot and create an application that notifies internal Reactors, adds data to Composables and otherwise does normal asynchronous tasks, but if you're not careful with how you nest these objects, where you create them, what Dispatcher you give them, and when you call accept, the application can suffer from race conditions, particularly around updating shared Composables and notifying a Reactor from inside a consumer on that Reactor.

It would be great to have a builder API that would allow you to build a Composable, say, that was properly configured for using from inside a Reactor's Consumer and other tasks where setting up several Reactor-based components are needed to work together.

from reactor.

wilkinsona avatar wilkinsona commented on July 23, 2024

To even further complicate this, I think we need to consider static state as a whole as part of this tidy up. I'm currently leaning towards removing all static state: it over-complicates things and seems like a recipe for classloading-related confusion. We'd lose the R helper class (in its current form, at least) but I think that's a price worth paying.

from reactor.

wilkinsona avatar wilkinsona commented on July 23, 2024

All static state has been removed from Reactor in 58bd8aa (I forgot to reference this issue in the commit message).

from reactor.

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.