Closed safareli closed 6 years ago
Also something like this can do the trick too:
p <- ask
resVar <- makeEmptyVar
let
acquire = do
runWeb3 p $ eth_newFilter $ fltr # _fromBlock .~ BN pollingFromBlock
release = case _ of
Left err -> putVar (Left err) resVar
Right filterId -> void $ runWeb3 p $ eth_uninstallFilter filterId
action = case _ of
Left err -> putVar (Left err) resVar
Right filterId -> do
res <- runWeb3 p $ void $ runProcess $ reduceEventStream (pollFilter filterId (fltr ^. _toBlock)) handler)
putVar res resVar
liftAff $ bracket acquire release action
res <- liftAff $ takeVar resVar
either throwError pure res
but if we don't add the MonadBracket instance then everyone would have to solve this issue over and over again.
fixes #97
see https://github.com/slamdata/purescript-aff#3-bracketing