how could one implement a function in concurrent haskell that either returns ‘a’ successfully or due to timeout ‘b’?
timed :: Int → IO a → b → IO (Either a b)
timed max act def = do
Best Regards,
Cetin Sert
Note: the signature of timed can be completely or slightly different.
Implementing your desired
timedon top ofSystem.Timeout.timeoutis easy:By the way, the common implementation of
timeoutis closer to this: ($!=seqto try to force evaluation of the returned value in the thread rather than only returning a thunk):The implementation of
System.Timeout.timeoutin the libraries is a little more complex, handling more exceptional cases.