-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to get code run on module shutdown #730
Comments
The requirement is to allow users to get code to run when a module is shutdown. A module This relates to #440 and #747, where one of the challenges is to get "sinks" (the thing you send events to) to deal with shutdown properly. |
We discussed the task module yesterday and again a similar need is present there. This is obviously a graceful shutdown of a module. |
The simple (no impact on any other part of the language) way to do this is to provide a |
We need to decide on order in which these handlers are called relative to each other and relative to the calls to gracefulStop on listeners. Currently the spec doesn't say anything about the relative order of calls to gracefulStop on listeners. Calls to the init method of a module happen after other initialization of the module but before any listeners are started. I think the normal thing is to do shutdown in reverse order of initialization, which would imply:
|
I agree that |
If module A imports module B, then if both module A and module B have an init function that registers a stop handler, then module B's call to onGracefulStop will happen before module A's call, but in my view module destruction should happen in reverse order of module construction (I don't think this is controversial) which means A's stop handler should be called before B's, which corresponds to the reverse of the order in which onGracefulStop is called. |
@warunalakshitha I have made the StopHandler return |
@jclark Should https://github.com/ballerina-platform/ballerina-spec/blob/master/lang/lib/runtime.bal#L67 |
Yes, that's a bug. Thanks. |
Description:
Currently we have a module
init
function for initialization in modules.We don't have a modulestop
function concept. It would be useful to have such a function.In my use case I initialize my mysql client at module
init
, it would be good to have a modulestop
function to close it.Code sample that shows issue:
The text was updated successfully, but these errors were encountered: