Skip to content

Instantly share code, notes, and snippets.

@anttih
Created March 18, 2018 14:18
Show Gist options
  • Save anttih/3400762028ae7cc641fe9bd34c8e21c9 to your computer and use it in GitHub Desktop.
Save anttih/3400762028ae7cc641fe9bd34c8e21c9 to your computer and use it in GitHub Desktop.
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