Skip to content

Instantly share code, notes, and snippets.

@oliver-batchelor
Created July 3, 2018 14:05
Show Gist options
  • Save oliver-batchelor/c982355133b6c1ee90de999517ca73a8 to your computer and use it in GitHub Desktop.
Save oliver-batchelor/c982355133b6c1ee90de999517ca73a8 to your computer and use it in GitHub Desktop.
timeout :: MonadWidget t m => (Event t a, Event t a) -> NominalDiffTime -> m (Event t a)
timeout (down, up) time = do
delayed <- delay time down
let timedOut = flip pushAlways down $ const $ mdo
isDown <- hold True (False <$ leftmost [up, delayed])
return $ gate isDown delayed
switchHold never timedOut
@oliver-batchelor
Copy link
Author

oliver-batchelor commented Jul 3, 2018

timeout :: GhcjsBuilder t m => (Event t a, Event t a) -> NominalDiffTime -> m (Event t a)
timeout (down, up) time = do
  delayed <- delay time down
  let gateDelay = do
      isDown <- hold True (False <$ leftmost [up, d])
      return $ gate isDown delayed

  switchHold never $ pushAlways f (const gateDelay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment