Files

48 lines
1.0 KiB
Standard ML
Raw Permalink Normal View History

structure Updater =
2024-10-06 09:32:56 +01:00
struct
open MailboxType
2025-08-04 09:29:37 +01:00
open InputMsg
2024-10-06 09:32:56 +01:00
fun sendMsg msg =
case msg of DRAW msg => DrawMailbox.append msg
2024-10-06 09:32:56 +01:00
fun sendMsgs msgList =
2024-10-06 09:32:56 +01:00
case msgList of
hd :: tl => let val () = sendMsg hd in sendMsgs tl end
2024-10-06 09:32:56 +01:00
| [] => ()
fun updateOne (app: AppType.app_type, inputMsg) =
2024-10-06 09:32:56 +01:00
let
val time = Time.now ()
2025-08-04 09:29:37 +01:00
val () =
case inputMsg of
CHAR_EVENT #"~" =>
ExceptionLogger.log (Fail "intentionally caused exception")
| _ => ()
val () = ExceptionLogger.addCommand inputMsg
val app = AppUpdate.update (app, inputMsg, time)
2025-08-06 00:16:50 +01:00
handle e => ExceptionLogger.log e
val () = sendMsgs (#msgs app)
2024-10-06 09:32:56 +01:00
in
app
2024-10-06 09:32:56 +01:00
end
fun updateLoop (pos, msgVec, app) =
if pos = Vector.length msgVec then
app
else
let
val msg = Vector.sub (msgVec, pos)
val app = updateOne (app, msg)
in
updateLoop (pos + 1, msgVec, app)
end
fun update app =
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
2024-10-06 09:32:56 +01:00
end