Created
March 18, 2018 14:18
-
-
Save anttih/3400762028ae7cc641fe9bd34c8e21c9 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
ticker :: Aff _ Unit | |
ticker = do | |
v1 <- makeEmptyVar | |
_ <- forkAff $ forever $ delay (Milliseconds 1000.0) *> putVar unit v1 | |
v2 <- makeEmptyVar | |
_ <- forkAff $ forever $ delay (Milliseconds 1000.0) *> putVar unit v2 | |
v3 <- liftAff makeEmptyVar | |
let | |
bounce = do | |
var <- makeEmptyVar | |
_ <- forkAff do | |
v <- takeVar v1 | |
putVar v var | |
takeVar var | |
go = void $ forkAff $ forever do | |
won <- sequential $ (Left <$> parallel bounce) <|> (Right <$> parallel (takeVar v2)) | |
putVar won v3 | |
void $ forkAff $ forever do | |
v <- takeVar v3 | |
case v of | |
Left _ -> liftEff $ log "left" | |
Right _ -> liftEff $ log "right" | |
go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment