-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathgeturls2.hs
More file actions
31 lines (24 loc) · 710 Bytes
/
geturls2.hs
File metadata and controls
31 lines (24 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import GetURL
import Control.Concurrent
import qualified Data.ByteString as B
-----------------------------------------------------------------------------
-- Our Async API:
-- <<async
data Async a = Async (MVar a)
async :: IO a -> IO (Async a)
async action = do
var <- newEmptyMVar
forkIO (do r <- action; putMVar var r)
return (Async var)
wait :: Async a -> IO a
wait (Async var) = readMVar var
-- >>
-----------------------------------------------------------------------------
-- <<main
main = do
a1 <- async (getURL "http://www.wikipedia.org/wiki/Shovel")
a2 <- async (getURL "http://www.wikipedia.org/wiki/Spade")
r1 <- wait a1
r2 <- wait a2
print (B.length r1, B.length r2)
-- >>