Joe
Joe

Reputation: 1564

Haskell hClose blocking

I am writing a Server in Haskell and I would like to explicitly close a clients Handle after they disconnect. When I call hClose, the thread will block until the Client closes their side of the handle. Is there a way to make it close without blocking?

Thanks in advance!

Upvotes: 6

Views: 287

Answers (1)

Thomas M. DuBuisson
Thomas M. DuBuisson

Reputation: 64740

Sure, just run it in another thread:

import Control.Concurrent (forkIO)

forkIO (hClose handle)

As jozefg has stated, you can use fancier solutions such as those found in async, but I don't see a reason to in this case.

Upvotes: 10

Related Questions