Last active
August 29, 2015 14:22
-
-
Save TerrorJack/1f1cb2e6f9cd93a8bed0 to your computer and use it in GitHub Desktop.
A simple concurrent crawler in Haskell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# OPTIONS_GHC -Wall -O2 -threaded -with-rtsopts="-N" #-} | |
| import Control.Concurrent | |
| import Control.Concurrent.Async.Pool | |
| import Data.ByteString.Lazy hiding (replicate) | |
| import Network.HTTP.Client | |
| import Network.HTTP.Client.TLS | |
| getConcurrently :: [String] -> IO [ByteString] | |
| getConcurrently urls = withManager tlsManagerSettings $ \mgr -> | |
| withTaskGroup 8 $ \tg -> mapConcurrently tg (\url -> do | |
| req <- parseUrl url | |
| responseBody <$> httpLbs req mgr <* threadDelay 0) urls | |
| main :: IO () | |
| main = getConcurrently (replicate 1024 "https://httpbin.org/get") >>= print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment