-
-
Save yamadapc/484eef307a0808499e1b 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 cb = do | |
putStrLn "[http] Fetching google.com" | |
threadDelay 1000 | |
putStrLn "[http] Fetching google.com/something" | |
threadDelay 1000 | |
cb "<html>...</html>" | |
-- Todo programa em Haskell tem uma função main | |
main = do | |
hSetBuffering stdout LineBuffering | |
-- Definimos um callback | |
let callback r = putStrLn ("callback: " ++ r) | |
-- Começamos nosso thread | |
forkIO (fazRequestsHTTP callback) | |
-- Essa linha vai ser impressa imediatamente | |
putStrLn "Eu apareço antes do callback ser executado!" | |
threadDelay 1000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment