Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active November 7, 2017 03:04
Show Gist options
  • Save iporsut/65e1a643474630e56c1cea02e59682f5 to your computer and use it in GitHub Desktop.
Save iporsut/65e1a643474630e56c1cea02e59682f5 to your computer and use it in GitHub Desktop.
Concurrent HTTP Get using Haskell
#!/usr/bin/env stack
-- stack --resolver lts-9.12 script --package http-conduit,stm,bytestring
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Lazy.Char8 as L8
import Control.Concurrent
import Control.Monad
import Control.Concurrent.STM
import Network.HTTP.Simple
main :: IO ()
main = do
queue <- (atomically $ newTBQueue 1000) :: IO (TBQueue ())
forkIO . forever $ do
atomically $ writeTBQueue queue ()
forkIO $ do
response <- httpLBS "http://httpbin.org/get"
L8.putStrLn $ getResponseBody response
threadDelay 1000000
atomically $ readTBQueue queue
getLine
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment