#Adding mist server under supervisor

1 messages · Page 1 of 1 (latest)

steel karma
#

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?

#

@eager bronze would appreciate any guide if you're available 🙏

terse cliff
#

Just write the function to erode the info that glisten’s starterror type gives you back into a normal actor start error

#

Mist is gonna most typically be used outside of supervision so it makes sense for it to have a start error type with more precision so the developer can handle different errors

#

But if you dont need that then you should write the function to take that info away and get back a regular ol’ start error, nothing wrong with that!

steel karma
#

Ah of course 😅 that train of thought makes a lot of sense, thanks @terse cliff 🙂

eager bronze
#

lol damn, guess i'm not needed again

terse cliff
#

Im sorry 😭😭

eager bronze
#

it's helpful and appreciated ofc 🙂

steel karma
#

Thanks @eager bronze 💜