Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save TerrorJack/1f1cb2e6f9cd93a8bed0 to your computer and use it in GitHub Desktop.

Select an option

Save TerrorJack/1f1cb2e6f9cd93a8bed0 to your computer and use it in GitHub Desktop.
A simple concurrent crawler in Haskell.
{-# 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