-
-
Save yamadapc/94afb7e8e2c92f822b1d 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
#!/usr/bin/env stack | |
-- stack runghc --package async | |
import Control.Concurrent | |
import Control.Concurrent.Async | |
import System.IO | |
fazRequestsHTTP = do | |
putStrLn "[http] Fetching google.com" | |
threadDelay 1000 | |
putStrLn "[http] Fetching google.com/something" | |
threadDelay 1000 | |
-- Retorna o resultado | |
return "<html>...</html>" | |
-- Todo programa em Haskell tem uma função main | |
main = do | |
hSetBuffering stdout LineBuffering | |
-- Começamos nosso thread | |
promessaParaResposta <- async fazRequestsHTTP | |
-- Essa linha vai ser impressa imediatamente | |
putStrLn "Eu apareço antes do callback ser executado!" | |
-- Esperamos pelo valor da promessa | |
valor <- wait promessaParaResposta | |
putStrLn ("valor: " ++ valor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment