Code Monkey home page Code Monkey logo

Comments (6)

BowenFu avatar BowenFu commented on July 23, 2024

Implement throw_, throwIO, and
onException io what
= io catch \e -> do _ <- what
throwIO (e :: SomeException)

from hspp.

BowenFu avatar BowenFu commented on July 23, 2024

data Async a = Async (MVar (Either SomeException a)) --
async :: IO a -> IO (Async a) async action = do
var <- newEmptyMVar
forkIO (do r <- try action; putMVar var r) -- return (Async var)
waitCatch :: Async a -> IO (Either SomeException a) -- waitCatch (Async var) = readMVar var
wait :: Async a -> IO a -- wait a = do
r <- waitCatch a case r of
Left e -> throwIO e
Right a -> return a

from hspp.

BowenFu avatar BowenFu commented on July 23, 2024

bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c bracket before after during = do
a <- before
c <- during a onException after a after a
return c

finally :: IO a -> IO b -> IO a finally io after = do
io onException after after

from hspp.

BowenFu avatar BowenFu commented on July 23, 2024

waitEither :: Async a -> Async b -> IO (Either a b) waitEither a b = do
m <- newEmptyMVar
forkIO $ do r <- try (fmap Left (wait a)); putMVar m r forkIO $ do r <- try (fmap Right (wait b)); putMVar m r wait (Async m)

from hspp.

BowenFu avatar BowenFu commented on July 23, 2024

waitAny :: [Async a] -> IO a waitAny as = do
m <- newEmptyMVar
let forkwait a = forkIO $ do r <- try (wait a); putMVar m r mapM_ forkwait as
wait (Async m)

from hspp.

BowenFu avatar BowenFu commented on July 23, 2024

Either has been implemented now.

from hspp.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.