I was trying to buld the scaffold of a web app built with mist and thought adding the resulting mist server as part of the supervision tree would be neat idea.
pub fn main() {
let assert Ok(_) = supervisor()
process.sleep_forever()
}
fn supervisor() {
supervisor.start(fn(children) {
children |> supervisor.add(server_childspec())
})
}
fn server_childspec() {
supervisor.supervisor(fn(_caller) { serve() })
}
fn serve() {
mist.new(pipeline)
|> mist.port(8088)
|> mist.start_http()
}
The above doesn't quite work because the supervision spec is expecting an actor.StartError type but mist does have a glisten.StartError.
error: Type mismatch
┌─ /Users/chouzar/Bench/Playground/cochito/src/cochito.gleam:26:25
│
26 │ supervisor.supervisor(fn(_caller) { serve() })
│ ^^^^^^^^^^^^^^^^^^^^^^^
Expected type:
fn(Nil) -> Result(Subject(Message), StartError)
Found type:
fn(Nil) -> Result(Subject(Message), glisten.StartError)
Does it make sense to add a mist server as part of the app supervision tree? Is it designed to be standalone?