Is it possible to make PostAndAsyncReply return immediately when its MailboxProcessor is disposed (or otherwise stopped)? Or is there some "pattern" / best practice on how to safely use PostAndReply methods without creating deadlocks?
Right now I have the problem that PostAndAsyncReply never returns when the MailboxProcessor has been disposed. Using the timeout parameter isn't an option since I cannot wait (besides that choosing reasonable timeouts is quite hard or impossible anyway since it depends on way too many factors).
[<Test>]
let ``waiting for a reply from a disposed agent``() =
use server = MailboxProcessor.Start(fun inbox -> async {
()
})
(server :> System.IDisposable).Dispose()
server.PostAndReply (fun reply -> reply) // <- deadlock
|> ignore)
edit: Most examples with MailboxProcessors I have seen (incl. the ones on MSDN) don't even mind disposing the MailboxProcessors. And the MSDN doesn't explain how MailboxProcessors react when being disposed. Is it unnecessary to dispose them?