takeMVar removes and returns the value stored in an MVar. When the MVar is empty, the calling thread blocks until another thread supplies a value with putMVar. section 8.1.3
Use takeMVar as the receiving step in synchronized thread communication:
- In request–response code, the requester takes the result from the response MVar after submitting a request. section 8.1.3
- A worker takes a request, processes it, and puts the response into the paired MVar. section 8.1.3
- Pair each takeMVar with a later putMVar; a missing putMVar can leave other threads blocked indefinitely. section 8.1.3
Receiving a processed response
sendRequest (request, response) value = do putMVar request value takeMVar response The final line waits until the worker has placed the result in the response MVar.
