#What is the correct way to use many actors through application and supervisor them?

1 messages · Page 1 of 1 (latest)

mild vale
#

Hello, I'm quite new to gleam coming from elixer and I am wondering if passing all of your actors subjects (lobby, games, active_players) via context for every request or in this case into the ws handler is the affective way of doing so?

let assert Ok(lobby) = lobby.create_lobby_actor()
let ctx = ws_handler.Context(lobby_sub: lobby)
// ...
 [] -> ws_handler.handle_ws_path(req, ctx)
// ...

Im more use to simply creating an elixer genserver or such, and utilizing the module name or atom.

#

Secondly, how would you access your actor's subject if its manged by a supervisor. Ive seen some example of how, but am unsure if its the most affective.

let parent_lobby_subj = process.new_subject()
// ... other subject of actors ...
let children = fn(children) {
  children
   |> supervisor.add(
      supervisor.worker(fn(_) {
        lobby.create_lobby_actor(parent: parent_lobby_subj ) 
       })
    )
 }
let assert Ok(_) = supervisor.start(children)
let ctx = ...