summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornitros12 <>2020-06-29 19:45:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-06-29 19:45:00 (GMT)
commite83c9df05b6c9dd8557e8f117b13c2e7f7926277 (patch)
treedeb6e6a59ff4b8564c84aa9aa2d52f49cbbbe557
parentd0ddbd47d51c77b36f8b82712ef3011e2ad8d2f8 (diff)
version 0.1.17.10.1.17.1
-rw-r--r--ChangeLog.md7
-rw-r--r--calamity.cabal4
-rw-r--r--src/Calamity/Client/Client.hs19
3 files changed, 18 insertions, 12 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index c25f95c..6225d83 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,5 +1,12 @@
# Changelog for Calamity
+## 0.1.17.1
+
+*2020-06-29*
+
+* `waitUntil` and `waitUntilM` now correctly remove the temorary event handler
+ they create if an exception is raised.
+
## 0.1.17.0
*2020-06-28*
diff --git a/calamity.cabal b/calamity.cabal
index 50cd499..1e5311c 100644
--- a/calamity.cabal
+++ b/calamity.cabal
@@ -4,10 +4,10 @@ cabal-version: 1.18
--
-- see: https://github.com/sol/hpack
--
--- hash: d52c65805c329ab185c6c81bf5373347ad1946bdeef8964dd4999f411797d6a2
+-- hash: 4cd6c5a80a55753413c0b839551d9d76dac6c32465e782b04be30aa1a16abf24
name: calamity
-version: 0.1.17.0
+version: 0.1.17.1
synopsis: A library for writing discord bots in haskell
description: Please see the README on GitHub at <https://github.com/nitros12/calamity#readme>
category: Network, Web
diff --git a/src/Calamity/Client/Client.hs b/src/Calamity/Client/Client.hs
index d329a58..fca4e7e 100644
--- a/src/Calamity/Client/Client.hs
+++ b/src/Calamity/Client/Client.hs
@@ -65,6 +65,7 @@ import qualified Polysemy.AtomicState as P
import qualified Polysemy.Error as P
import qualified Polysemy.Fail as P
import qualified Polysemy.Reader as P
+import qualified Polysemy.Resource as P
import TextShow ( TextShow(showt) )
@@ -237,12 +238,11 @@ waitUntil
( BotC r, ReactConstraints s)
=> (EHType s -> Bool)
-> P.Sem r (EHType s)
-waitUntil f = do
+waitUntil f = P.resourceToIOFinal $ do
result <- P.embed newEmptyMVar
- remove <- react @s (checker result)
- res <- P.embed $ takeMVar result
- remove
- pure res
+ P.bracket (P.raise $ react @s (checker result))
+ P.raise
+ (const . P.embed $ takeMVar result)
where
checker :: MVar (EHType s) -> EHType s -> P.Sem r ()
checker result args = do
@@ -277,12 +277,11 @@ waitUntilM
( BotC r, ReactConstraints s)
=> (EHType s -> P.Sem r Bool)
-> P.Sem r (EHType s)
-waitUntilM f = do
+waitUntilM f = P.resourceToIOFinal $ do
result <- P.embed newEmptyMVar
- remove <- react @s (checker result)
- res <- P.embed $ takeMVar result
- remove
- pure res
+ P.bracket (P.raise $ react @s (checker result))
+ P.raise
+ (const . P.embed $ takeMVar result)
where
checker :: MVar (EHType s) -> EHType s -> P.Sem r ()
checker result args = do