The server should implement the Erlang/OTP application callbacks instead of manually starting with let assert and process.sleep_forever()
Something like in bowtie_server.gleam
/// The Erlang/OTP application start callback.
/// Responsible to start the "top" supervisor process and return its Pid
/// to the application controller.
pub fn start(_app: atom.Atom, _type: a) -> Result(process.Pid, actor.StartError) {
case start_supervisor() {
Ok(actor.Started(pid, _data)) -> {
let sup_name = process.new_name("bowtie")
let _ = process.register(pid, sup_name)
Ok(pid)
}
Error(reason) -> Error(reason)
}
}
/// The Erlang/OTP application stop callback.
/// This is called after all processes in the supervisor tree have
/// been shutdown by the application controller. Responsible for any
/// final clean up actions.
pub fn stop(_state: a) -> atom.Atom {
atom.create("ok")
}
Where start_supervisor has the content of the current main()
(Without the let assert and process.sleep_forever ofc)
You'd also need to add the application start module to the gleam.toml like this:
[erlang]
application_start_module = "bowtie_server"
This way the beam can actually restart the server if/when it crashes