Skip to content

Instantly share code, notes, and snippets.

@calledtoconstruct
Created February 8, 2021 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calledtoconstruct/67efbd2b744d027a0ad136ee1cd3a13d to your computer and use it in GitHub Desktop.
Save calledtoconstruct/67efbd2b744d027a0ad136ee1cd3a13d to your computer and use it in GitHub Desktop.
read_module_state_web_request
Types Signatures:
type Dashboard = ModuleT DashboardState LB
newtype LB a = LB {unLB :: ReaderT (IRCRState, IORef IRCRWState) IO a}
newtype ModuleT st m a = ModuleT {unModuleT :: ReaderT (ModuleInfo st) m a}
data DashboardState = ...
listViewers :: String -> DashboardState -> [String]
scotty :: Port -> ScottyM () -> IO ()
get :: RoutePattern -> ActionM () -> ScottyM ()
Where issue occurs:
startListening :: Int -> Dashboard ()
startListening port = do
debugM "Starting Server..."
-- dashboardState <- readMS
-- ^^^ this works fine, except that the state is not kept up to date as it is a copy at this point
threadId <- fork $
liftIO $
scotty port $ do
middleware simpleCors
get (capture "/:channel/viewer/list") $ do
requestedChannel <- param (T.pack "channel")
dashboardState <- readMS
let viewerList = listViewers requestedChannel dashboardState
json viewerList
-- ^^^ this does not work due to the following two errors
_ :: ActionT Text IO (LBState (ActionT Text IO))
• No instance for (MonadLBState (Web.Scotty.Internal.Types.ActionT T.Text IO))
arising from a use of ‘readMS’
_ :: DashboardState
• Couldn't match expected type ‘DashboardState’ with actual type ‘Lambdabot.State.LBState (Web.Scotty.Internal.Types.ActionT T.Text IO)’
• In the second argument of ‘listViewers’, namely ‘dashboardState’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment