-
-
Save yamadapc/6d75b4664f5845e38d26 to your computer and use it in GitHub Desktop.
This file contains 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
import Control.Concurrent | |
import System.IO | |
fazRequestsHTTP mvar = do | |
putStrLn "[http] Fetching google.com" | |
threadDelay 1000 | |
putStrLn "[http] Fetching google.com/something" | |
threadDelay 1000 | |
putMVar mvar "<html>...</html>" | |
-- Todo programa em Haskell tem uma função main | |
main = do | |
hSetBuffering stdout LineBuffering | |
-- Criamos uma MVar vazia para a resposta | |
caixinhaParaAResposta <- newEmptyMVar | |
-- Começamos nosso thread | |
forkIO (fazRequestsHTTP caixinhaParaAResposta) | |
-- Essa linha vai ser impressa imediatamente | |
putStrLn "Eu apareço antes do callback ser executado!" | |
-- Esperamos até ter um valor na caixinha | |
valor <- takeMVar caixinhaParaAResposta | |
putStrLn ("valor: " ++ valor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment