Sorcery.PortalServer (sorcery v0.4.4)

A PortalServer is a special type of GenServer. Portals are created between different PortalServers, always in a hierarchical parent <--> child relationship.

Every PortalServer must have access to some kind of data store. That might be Postgres via Ecto.Repo... or it could be a LiveView storing data in socket.assigns. (Remember, LiveViews are GenServers!) You can even create your own adapter and use ANY backend as the data store, as long as you can query and mutate the data.

Setup

A PortalServer is any GenServer that holds a special :sorcery key somewhere in its state, and also handles messages sent to {:sorcery, msg}

Summary

Functions

To convert any process into a PortalServer, you must follow 2 steps

Functions

Link to this function

add_portal_server_state(outer_state, opts)

To convert any process into a PortalServer, you must follow 2 steps:

  1. Add some PortalServer configuration to the state
  2. Implement the PortalServer handlers for a handle_info function
use GenServer
use Sorcery.PortalServer

def init(_) do
  state = %{} # You can still add whatever you want here

  state = Sorcery.PortalServer.add_portal_server_state(state, %{
    config_module: Src,
    store_adapter: Sorcery.StoreAdapters.Ecto,

    # This depends on the adapters you use
    args: %{
      repo_module: MyApp.Repo
    }
  })

  {:ok, state}
end