Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
5a3a3172
Commit
5a3a3172
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite observeBlocking for new observable signature
Co-authored-by:
Jan Beinke
<
git@janbeinke.com
>
parent
90cea54d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Observable.hs
+14
-35
14 additions, 35 deletions
src/Quasar/Observable.hs
with
14 additions
and
35 deletions
src/Quasar/Observable.hs
+
14
−
35
View file @
5a3a3172
...
...
@@ -113,41 +113,20 @@ class IsRetrievable v o => IsObservable v o | o -> v where
-- | Observes an observable by handling updates on the current thread.
observeBlocking
::
(
IsObservable
v
o
,
MonadResourceManager
m
)
=>
o
->
(
ObservableMessage
v
->
m
()
)
->
m
a
observeBlocking
observable
callback
=
do
msgVar
<-
liftIO
$
newTVarIO
ObservableLoading
idVar
<-
liftIO
$
newTVarIO
(
0
::
Word64
)
calledIdVar
<-
liftIO
$
newTVarIO
(
0
::
Word64
)
completedVar
<-
newAsyncVar
resourceManager
<-
askResourceManager
finally
do
bracketOnError
do
-- This implementation is a temporary compatability wrapper and forking isn't necessary with the new design.
forkTask
do
attachDisposable
resourceManager
=<<
liftIO
do
oldObserve
observable
\
msg
->
do
currentMsgId
<-
atomically
do
writeTVar
msgVar
msg
stateTVar
idVar
(
dup
.
(
+
1
))
-- Wait for `callback` to complete
awaitAny2
do
toAwaitable
completedVar
do
unsafeAwaitSTM
do
readTVar
calledIdVar
>>=
\
calledId
->
unless
(
calledId
>=
currentMsgId
)
retry
do
disposeAndAwait
do
const
$
forever
do
(
msgId
,
msg
)
<-
liftIO
$
atomically
do
msgAvailable
<-
liftA2
(
>
)
(
readTVar
idVar
)
(
readTVar
calledIdVar
)
unless
msgAvailable
retry
liftA2
(,)
(
readTVar
idVar
)
(
readTVar
msgVar
)
callback
msg
liftIO
$
atomically
$
writeTVar
calledIdVar
msgId
do
putAsyncVar
completedVar
()
withSubResourceManagerM
do
var
<-
liftIO
newEmptyTMVarIO
observe
observable
\
msg
->
do
liftIO
$
atomically
do
cbCompletedVar
<-
tryTakeTMVar
var
>>=
\
case
Nothing
->
newAsyncVarSTM
Just
(
_
,
cbCompletedVar
)
->
pure
cbCompletedVar
putTMVar
var
(
msg
,
cbCompletedVar
)
pure
$
toAwaitable
cbCompletedVar
forever
do
(
msg
,
cbCompletedVar
)
<-
liftIO
$
atomically
$
takeTMVar
var
callback
msg
putAsyncVar_
cbCompletedVar
()
asyncObserve
::
IsObservable
v
o
=>
MonadAsync
m
=>
o
->
(
ObservableMessage
v
->
m
()
)
->
m
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment