.net - PostAndAsyncReply deadlock on exception -


given 2 agents, communicates sending messages:

agent 1 sends postandasyncreply agent 2, waiting result.

agent 2 starts processing message, throws exception.

now agent 1 deadlocked, since no reply ever sent agent 1. see it, there 2 ways handle such scenario:

  1. i set timeout postandasyncreply, since operation long running, time takes execute differs.

  2. wrap code in agent 2 in try..catch, , reply value indicates error. however, mean code handles messages replychannel, needs wrapped inside try..catch, seems.. cumbersome.

how 1 go around handling such scenario?

you have higher-order function alleviates try...catch:

let replyorfail (chan: asyncreplychannel<option<'t>>) (action: async<'t>) : async<unit> =     async {         try             let! reply = action             return chan.reply (some reply)         _ ->             return chan.reply none     }  let agent2 =     (* declare mailbox... *)     (* matching received message: *)     | messagefromagent1 chan ->         do! replyorfail chan <| async {             return! longcomputationthatmightthrow()         }     (* ... *) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -