Git Product home page Git Product logo

Comments (5)

matthewp avatar matthewp commented on September 23, 2024 2

Normally you would call context.actorRef.stop() in an action, right? You an currently do that, I think. But it might be nice to have a lucy native way. Maybe:

machine todoItem {
  state idle {}
}

machine app {
  state idle {
    new => assign(todo, spawn(todoItem))

    delete => stop(todo)
  }
}

from liblucy.

mattpocock avatar mattpocock commented on September 23, 2024

This looks cool. One thing which might affect spawn in general is how we represent arrays of spawned actors? Though perhaps this should be the topic for another issue.

from liblucy.

matthewp avatar matthewp commented on September 23, 2024

Yeah lists are going to be needed eventually, I intentionally avoided that so far.

from liblucy.

VanTanev avatar VanTanev commented on September 23, 2024

Normally you would call context.actorRef.stop() in an action, right?

Unfortunately, no. The proper way to stop a spawned child is this:

{
  on: {
    STOP: actions.pure((ctx) => {
      const assignAction = assign({ actorRef: null })
      const stopAction = actions.stop(ctx.actorRef)
      
      return [assignAction, stopAction]
    })
  }
}

XState v5 should improve this, but for now, the above code is the only way to stop a child actor without leaking memory. Simply calling ctx.actorRef.stop() still leaves a dangling reference in machine.children, while actions.stop() will properly clean up all references.

Because assign() executes before all other actions, you can't simply have:

actions: [
  // doesn't work, assign() will execute before stop(), and `ctx.actorRef` will be null, so nothing will be stopped.
  actions.stop(ctx => ctx.actorRef),
  assign({ actorRef: null })
]

It must be wrapped in actions.pure().

from liblucy.

matthewp avatar matthewp commented on September 23, 2024

@VanTanev Thank you! Seems like something Lucy can do the gross part for you.

from liblucy.

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.