Comments (5)
A service.stop()
would be a good feature to add though.
from robot.
I don't think I understand the bug. You send 2 events to the service which puts it into the child machine. You then create a new service. That doesn't stop the in-flight setTimeout
from happening.
Creating a new service doesn't "stop" the existing service. There isn't presently a way to stop a service that's already running, aside from not sending events into it any more.
from robot.
@matthewp any suggestions how this can be achieved?
And also don't you find this wrong that reference can be removed and you loose control over state machine, but service is still running?
from robot.
Add a stop() function here: https://github.com/matthewp/robot/blob/main/machine.js#L189 that probably just sets a this.stopped = true
. Then probably send() checks if the service is stopped at the top of the function and exits if so: https://github.com/matthewp/robot/blob/main/machine.js#L169
No, I don't think this is wrong, that's just how JavaScript works. If you don't keep a reference to an object that does stuff... it's going to keep doing stuff.
I do think your example is not something you'd want to happen! That's why I suggested a stop().
However, even with a stop() it's not going to prevent the Promise from resolving. So if there are any mutations inside of the setTimeout handler those are still going to happen. Nothing we can do about that. But we can avoid the machine from continuing to change.
from robot.
@matthewp maybe you are right.
Im my appp I use state machine as session manager. So sometime people leave in the middle of the session and it is destoyed (at least I thought it was the case) after timeout. Now it is a memory leak in my case
Another option was to implement "terninate" transition for each state, but my app is too big to do so.
from robot.
Related Issues (20)
- Why it moves to the wrong state? HOT 1
- Docs on `interpret` confusing HOT 3
- Docs: API-wide nav
- API: Consider renaming `interpret()` to `createService()` HOT 4
- Deadly traffic light HOT 3
- What's the differences between robot and @xstate/fsm HOT 1
- [Question] Using the returned objects in place of the function calls HOT 2
- A library to visualise Robot3 state machines HOT 1
- `onChange` not called for `immediate` states HOT 3
- Allow `action()`s to send events back to the fsm HOT 2
- invoke dynamic child machines HOT 5
- Bring integrations into the main repo
- Get CI setup
- Automate release process
- The machine's current state is not updated when send is triggered HOT 1
- initialContext is not set HOT 1
- Problem with es modules with next.js HOT 9
- [bug?] Nested machines immediate issue HOT 1
- Infinite loop if machine is created anew each render
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robot.