Comments (6)
Implement throw_, throwIO, and
onException io what
= io catch
\e -> do _ <- what
throwIO (e :: SomeException)
from hspp.
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.
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.
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.
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.
Either has been implemented now.
from hspp.
Related Issues (11)
- Implement std::future monad.
- Implement STM.
- Implement STM
- Provide a pretty printer to skip unwanted frames in gdb / lldb.
- Implement Haskell Coroutine.
- Fix sample/pause.cpp build for msvc.
- Fix win build for coroutine.
- Change Maybe to an alias of optional and implement sample for C++ monadic interface. HOT 1
- Add a readme `from proposal to hspp` for std::optional (Maybe) / std::expected (Either) introduction.
- Implement CycleView. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hspp.