我可以寫這樣的事情如何通過websocket實現服務器推送?
let echo (ws: WebSocket) =
fun ctx -> socket {
let loop = ref true
while !loop do
let! message = Async.Choose (ws.read()) (inbox.Receive())
match message with
| Choice1Of2 (wsMessage) ->
match wsMessage with
| Ping, _, _ -> do! ws.send Pong [||] true
| _ ->()
| Choice2Of2 pushMessage -> do! ws.send Text pushMessage true
}
或者我需要2個獨立的插座迴路併發讀 - 寫?
能否請您提出一個很好Async.Choose的實現對於這種情況?並關於太循環:是[這](https://github.com/SuaveIO/suave/issues/307#issuecomment-146873334)好?謝謝! –
我認爲你的雙循環實現有線程安全問題(從2個線程寫入) –