Coder Social home page Coder Social logo

Comments (8)

garyb avatar garyb commented on June 28, 2024 2

I think the case you're exploring there is a little different from how this was experienced.

I'm saying a child disappearing killed the current eval in the parent component. I agree that a child being removed should terminate any actions it is taking, I don't agree that it should also kill the eval that performed the removal when that eval arose from the child raising a message.

That doesn't seem like "cancelling a child's pending actions", since we're in the context of the parent at this point.

from purescript-halogen.

garyb avatar garyb commented on June 28, 2024

I've found another issue related to this: if you're handling the message from a child, and within that eval you modify the state in such a way that the child is removed, it will immediately terminate the eval after the state change. So:

HandleChildMessage _ -> do
  traceM "Hello"
  H.modify_ removeTheChildThatRaisedThisMessage
  traceM "Goodbye"

The traceM "Goodbye" is unreachable here.

from purescript-halogen.

natefaubion avatar natefaubion commented on June 28, 2024

I think that case is reasonable, where removing a child is equivalent to cancelling the child's pending actions. That is, it's equivalent to sending a kill to all fork ids, which is certainly a thing Halogen already exposes as part of it's API. I think that if you needed guarantees around uncancellable blocks of HalogenM, you'd need to provide an API for that (such as invincible).

from purescript-halogen.

thomashoneyman avatar thomashoneyman commented on June 28, 2024

I think that case is reasonable, where removing a child is equivalent to cancelling the child's pending actions. That is, it's equivalent to sending a kill to all fork ids, which is certainly a thing Halogen already exposes as part of it's API. I think that if you needed guarantees around uncancellable blocks of HalogenM, you'd need to provide an API for that (such as invincible).

That's not what I would intuitively expect; the child notified the parent of a message, but that doesn't mean the parent will necessarily react by interacting with the child further.

As an analogy, if I am handling a click event in the DOM, I wouldn't expect my handler to get cancelled halfway through because the element that was clicked was removed in the meantime (though I would expect that attempting to interact with that element would now fail, the same way that H.query will fail if the indicated child component has been removed)

from purescript-halogen.

natefaubion avatar natefaubion commented on June 28, 2024

But DOM handlers are synchronous and linear. Code in HalogenM is asynchronous and concurrent (regardless of what your m is), so it requires concurrency semantics.

from purescript-halogen.

natefaubion avatar natefaubion commented on June 28, 2024

Perhaps another way of phrasing it:

someHalogenM = do
  raise ...
  lift $ Console.log "Hello"

eval = do
  SomeAction ->
    someHalogenM
  AnotherAction ->
    void $ H.fork someHalogenM

What happens here? There are a few possibilities:

  • SomeAction continues execution because it's a "root eval" (ie not forked by the user), AnotherAction gets cancelled because it s a fork.
  • They both continue execution because removing a child never invokes a cancellation of component fibers. This leads to pervasive leaks because you can never run potentially infinite async loops.
  • They are both cancelled because the runtime treats managed forks (those forked by the runtime) identically to user forks.

To me, the third option is the only composable behavior since it's uniform. The first gives you observable differences in behavior, and IMO is non-composable since every root action gets the equivalent to an implicit invincible. This means if you ever run an async loop of some kind, you need to remember to fork it or it will always leak.

The concurrency semantics of Aff (which Halogen piggy backs on) are such that everything is cancellable by default. If things should not be cancellable, then they need to be invoked through explicit regions (bracket, invincible, etc). I personally don't consider runtime managed forks to be an explicit region.

from purescript-halogen.

natefaubion avatar natefaubion commented on June 28, 2024

Oh, I see. I misunderstood the example. I should have read closer. Yes, I agree with you that a child disappearing should not result in the parent halting execution.

It sounds like the parent execution is being run within the context of the child's fiber execution.

from purescript-halogen.

garyb avatar garyb commented on June 28, 2024

Yeah, I'm pretty sure that's exactly the problem. 👍

It's a confusing example 😄

from purescript-halogen.

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.