I have a timeout exception (and I really intend to set a timeout) inside a message loop and I have tried to catch it as follows
let printerAgent = MailboxProcessor.Start(fun inbox->
// the message processing function
let rec messageLoop() = async{
try
// read a message
let! msg = inbox.Receive 30000
// process a message
match msg with
| Message text ->
sw.WriteLine("{0}: {1}", DateTime.UtcNow.ToShortTimeString(), text)
printfn "%s" text
// loop to top
return! messageLoop()
| Shutdown replyChannel ->
replyChannel.Reply()
// We do NOT do return! messageLoop() here
with
| exc ->
printfn "%s" exc.Message
}
// start the loop
messageLoop()
)
and I can see the timout message printed in the console, but the program never ends: what am I missing?
This is how I'm calling the printerAgent
in my code
printerAgent.PostAndReply( (fun replyChannel -> Shutdown replyChannel), 10000)
Notice that with inbox.Receive()
it eventually terminates fine after a few minutes but my objective is setting a timeout (for example of 30 seconds) instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…