Skip to content

Instantly share code, notes, and snippets.

@safareli
Created February 27, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safareli/af035dcbbab8abfb519a70e77e654110 to your computer and use it in GitHub Desktop.
Save safareli/af035dcbbab8abfb519a70e77e654110 to your computer and use it in GitHub Desktop.
performs delay untill next animation frame using requestAnimationFrame
-- | performs delay untill next animation frame.
untilNextAnimationFrame :: Aff Unit
untilNextAnimationFrame = do
var <- AVar.empty
w <- liftEffect $ window
Aff.bracket
(liftEffect $ requestAnimationFrame (launchAff_ $ AVar.put unit var) w)
(\requestAnimationFrameId -> liftEffect $ cancelAnimationFrame requestAnimationFrameId w)
(\_ -> AVar.take var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment