Last active
November 7, 2017 03:04
-
-
Save iporsut/65e1a643474630e56c1cea02e59682f5 to your computer and use it in GitHub Desktop.
Concurrent HTTP Get using 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
#!/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