Allow "destroying" the environment to properly shutdown services #1446
Replies: 1 comment 6 replies
-
This ask makes sense, our intent is definitely for cleanup to be covered by the environment. It's possible Originally the intent was for the environment to "own" services and I think the asyncDispose interface method is an artifact of that. However this meant there's no way to make an external component available as a dependency without assigning ownership. So we added Rather than listening to So my inclination is that we should just remove Which isn't to say we can't consider adding a "close" concept to Environment.ts... Just need to think through the "publish without assigning ownership" case and how to differentiate environment close from runtime cancel. Maybe we could add an additional symbol property to |
Beta Was this translation helpful? Give feedback.
-
I'd like to use the
environment
as some kind of "dependency injection" tool to pass custom services into my behaviors.Some services require async initialization and async disposal.
As
environment.set
already suggests, I can register my own services. Additionallyenvironment.load
already considers async initialization and waits for it to be finished.The corresponding interface
Environmental.Service
already includes an optionalasyncDispose
function, which is described as follows:Anyway there seems to be no way to "destroy" the environment. Additionally I couldn't find any place in matter.js where this is called for
#services
.Even when using process signals to stop the app,
asyncDispose
doesn't get called.As a workaround I made every service listen for
environment.runtime.stopped
orcrashed
to dispose itself.Beta Was this translation helpful? Give feedback.
All reactions