-- | Run a set of handlers over a value.
dispatchHandlers :: HandlerMap a -> a -> IO ()
dispatchHandlers hs a = mapM_ run (Map.toList (handlers hs))
  where
  run (ref,k) = k ref a `X.catch` handler

  -- swallow exceptions to prevent handlers from killing the enclosing thread
  handler :: X.SomeException -> IO ()
  handler e = do
    putStrLn "Encountered exception, swallowing."
    print e
    return ()
dispatchHandlers :: HandlerMap a -> a -> IO ()
dispatchHandlers hs a = mapM_ run (Map.toList (handlers hs))
  where
  run (ref,k) = k ref a `X.catch` handler

  -- swallow exceptions to prevent handlers from killing the enclosing thread
  handler :: X.SomeException -> IO ()
  handler e = do
    putStrLn "Encountered exception, swallowing."
    print e
    return ()
dispatchHandlers hs a = mapM_ run (Map.toList (handlers hs))
  where
  run (ref,k) = k ref a `X.catch` handler

  -- swallow exceptions to prevent handlers from killing the enclosing thread
  handler :: X.SomeException -> IO ()
  handler e = do
    putStrLn "Encountered exception, swallowing."
    print e
    return ()