Created
October 15, 2015 20:54
-
-
Save teh/7da27e48b74ec658dd4d to your computer and use it in GitHub Desktop.
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
import Reactive.Banana (compile) | |
import Reactive.Banana.Frameworks (newAddHandler, fromAddHandler, actuate, reactimate) | |
import Control.Concurrent (threadDelay, forkIO) | |
import Control.Monad (forever) | |
import Data.Char (toUpper) | |
main = do | |
-- newAddHandler returns an AddHandler (roughly a callback) and a | |
-- way to fire the callback (fire). | |
(es, fire) <- newAddHandler | |
-- We fire the handler with the value "hello" every 100 ms. | |
forkIO $ forever $ do | |
threadDelay (1000 * 100) | |
fire "hello" | |
-- Create a simple reactive network that prints the value passed | |
-- to the callback, once as passed, then as uppercase. | |
network <- compile $ do | |
c <- fromAddHandler es | |
reactimate $ fmap print c | |
reactimate $ fmap print (fmap (map toUpper) c) | |
-- actuate "activates" the network (registers callbacks etc.), can | |
-- be paused with `pause` | |
actuate network | |
getLine >> return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment