Skip to content
Snippets Groups Projects
Commit 499e0256 authored by Jens Nolte's avatar Jens Nolte
Browse files

Fix compatability observe implementaton

parent c3c90379
No related branches found
No related tags found
No related merge requests found
Pipeline #2416 passed
...@@ -91,20 +91,29 @@ class IsRetrievable v o => IsObservable v o | o -> v where ...@@ -91,20 +91,29 @@ class IsRetrievable v o => IsObservable v o | o -> v where
idVar <- liftIO $ newTVarIO (0 :: Word64) idVar <- liftIO $ newTVarIO (0 :: Word64)
calledIdVar <- liftIO $ newTVarIO (0 :: Word64) calledIdVar <- liftIO $ newTVarIO (0 :: Word64)
resourceManager <- askResourceManager
bracketOnError bracketOnError
do do
liftIO $ unsafeAsyncObserveIO observable \msg -> do -- HACK: use async to fork on MonadResourceManager
currentMessage <- atomically do -- This should use MonadAsync instead, but this implementation is a temporary compatability wrapper and the
writeTVar msgVar msg -- constraints are based on the new design.
stateTVar idVar (dup . (+ 1)) liftIO $ onResourceManager resourceManager $ async do
-- Wait for `callback` to complete attachDisposable resourceManager =<< liftIO do
atomically do unsafeAsyncObserveIO observable \msg -> do
readTVar calledIdVar >>= \called -> currentMsgId <- atomically do
unless (called >= currentMessage) retry writeTVar msgVar msg
stateTVar idVar (dup . (+ 1))
-- Wait for `callback` to complete
atomically do
readTVar calledIdVar >>= \calledId ->
unless (calledId >= currentMsgId) retry
do disposeAndAwait do disposeAndAwait
do do
const $ forever do const $ forever do
(msgId, msg) <- liftIO $ atomically $ liftA2 (,) (readTVar idVar) (readTVar msgVar) (msgId, msg) <- liftIO $ atomically do
msgAvailable <- liftA2 (>) (readTVar idVar) (readTVar calledIdVar)
unless msgAvailable retry
liftA2 (,) (readTVar idVar) (readTVar msgVar)
callback msg callback msg
liftIO $ atomically $ writeTVar calledIdVar msgId liftIO $ atomically $ writeTVar calledIdVar msgId
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment