NeoHaskell
NeoHaskell copied to clipboard
Add Comprehensive Error Handling in mainWorker Function
trafficstars
The function mainWorker in core/platform/Platform.hs lacks error handling for potential failures in the main event loop. Consider adding error handling to ensure robustness.
Relevant PR: https://github.com/neohaskell/NeoHaskell/pull/82 Comment URL: https://github.com/neohaskell/NeoHaskell/pull/82#discussion_r1693458445
mainWorker userApp eventsQueue modelRef commandsQueue =
Monad.forever do
print "Reading next event"
msg <- Channel.read eventsQueue
print "Getting model"
model <- ConcurrentVar.get modelRef
print ("Got model: " ++ toText model)
print "Updating model"
let (newModel, newCmd) = userApp.update msg model
print
( "New model: "
++ toText newModel
++ "New command: "
++ toText newCmd
)
print "Setting new model"
modelRef |> ConcurrentVar.set newModel
print "Writing new command"
commandsQueue |> Channel.write newCmd
`catch` \e -> do
print ("Failed to write new command: " ++ show e)
This issue has been created based on the review comment by @coderabbitai[bot].