-
-
Notifications
You must be signed in to change notification settings - Fork 69
Application module #118
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
base: main
Are you sure you want to change the base?
Application module #118
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,170 @@ | ||||||
| //// In the context of the OTP framework an "application" is a collection of | ||||||
| //// code that can be loaded into the virtual machine. Each Gleam package is a | ||||||
| //// single OTP application. | ||||||
| //// | ||||||
| //// One feature of OTP applications that makes them different from packages or | ||||||
| //// libraries in other languages is that they have the option of defining a | ||||||
| //// module through which they can be _started_ and _stopped_, and they can | ||||||
| //// configured using Erlang's configuration system. | ||||||
| //// | ||||||
| //// ## OTP application programs | ||||||
| //// | ||||||
| //// Long running Gleam programs (such as backend web applications) typically | ||||||
| //// want to define an application module, and to use it as the entrypoint for | ||||||
| //// the program in favour of the `main` function. | ||||||
| //// | ||||||
| //// ## OTP application libraries | ||||||
| //// | ||||||
| //// It is always preferred for libraries to not be stateful! Instead they | ||||||
| //// should expose functions for Gleam apps to call, passing configuration as | ||||||
| //// arguments. There may be some libraries for which it makes sense to have | ||||||
| //// this implicit global mutable state, but they are very rare. | ||||||
| //// | ||||||
|
|
||||||
| // TODO: give example of how to use it | ||||||
|
|
||||||
| import gleam | ||||||
| import gleam/erlang/atom.{type Atom} | ||||||
| import gleam/erlang/node | ||||||
| import gleam/erlang/process | ||||||
| import gleam/otp/actor | ||||||
|
|
||||||
| /// A recipe of how to start the stateful OTP application. | ||||||
| /// | ||||||
| /// See the module documentation for how to use this type in your program. | ||||||
| /// | ||||||
| pub opaque type Application(state) { | ||||||
| Application( | ||||||
| start: fn(StartType) -> actor.StartResult(state), | ||||||
| before_stop: fn(state) -> state, | ||||||
| after_stop: fn(state) -> Nil, | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| // TODO: test | ||||||
| /// Create a new application recipe from a starter function. This function is | ||||||
| /// called whenever an application is started, and it starts the supervision tree | ||||||
| /// the OTP application. | ||||||
|
||||||
| /// the OTP application. | |
| /// of the OTP application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre_stop -> prep_stop ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.