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
9e5b3c2b
Commit
9e5b3c2b
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Change resource manager api (for awaitable disposables)
parent
7f26db8d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2390
passed
3 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/Core.hs
+9
-9
9 additions, 9 deletions
src/Quasar/Core.hs
src/Quasar/Observable.hs
+16
-14
16 additions, 14 deletions
src/Quasar/Observable.hs
with
25 additions
and
23 deletions
src/Quasar/Core.hs
+
9
−
9
View file @
9e5b3c2b
...
@@ -33,7 +33,7 @@ module Quasar.Core (
...
@@ -33,7 +33,7 @@ module Quasar.Core (
synchronousDisposable
,
synchronousDisposable
,
noDisposable
,
noDisposable
,
disposeEventually
,
disposeEventually
,
bound
Disposable
,
attach
Disposable
,
attachDisposeAction
,
attachDisposeAction
,
attachDisposeAction_
,
attachDisposeAction_
,
)
where
)
where
...
@@ -283,8 +283,8 @@ instance IsDisposable EmptyDisposable where
...
@@ -283,8 +283,8 @@ instance IsDisposable EmptyDisposable where
newDisposable
::
IO
(
Awaitable
()
)
->
IO
Disposable
newDisposable
::
MonadIO
m
=>
IO
(
Awaitable
()
)
->
m
Disposable
newDisposable
=
fmap
(
toDisposable
.
FnDisposable
)
.
newTMVarIO
.
Left
newDisposable
=
liftIO
.
fmap
(
toDisposable
.
FnDisposable
)
.
newTMVarIO
.
Left
synchronousDisposable
::
IO
()
->
IO
Disposable
synchronousDisposable
::
IO
()
->
IO
Disposable
synchronousDisposable
=
newDisposable
.
fmap
pure
.
liftIO
synchronousDisposable
=
newDisposable
.
fmap
pure
.
liftIO
...
@@ -303,15 +303,15 @@ disposeEventually _resourceManager disposable = liftIO $ do
...
@@ -303,15 +303,15 @@ disposeEventually _resourceManager disposable = liftIO $ do
Just
(
Right
()
)
->
pure
()
Just
(
Right
()
)
->
pure
()
Nothing
->
undefined
-- TODO register on resourceManager
Nothing
->
undefined
-- TODO register on resourceManager
-- | Creates an `Disposable` that is bound to a ResourceManager. It will automatically be disposed when the resource manager is disposed.
attachDisposable
::
(
IsDisposable
a
,
MonadIO
m
)
=>
ResourceManager
->
a
->
m
()
boundDisposable
::
HasResourceManager
m
=>
IO
(
Awaitable
()
)
->
m
Disposable
attachDisposable
_resourceManager
disposable
=
undefined
boundDisposable
action
=
do
resourceManager
<-
askResourceManager
attachDisposeAction
resourceManager
action
-- | Creates an `Disposable` that is bound to a ResourceManager. It will automatically be disposed when the resource manager is disposed.
-- | Creates an `Disposable` that is bound to a ResourceManager. It will automatically be disposed when the resource manager is disposed.
attachDisposeAction
::
MonadIO
m
=>
ResourceManager
->
IO
(
Awaitable
()
)
->
m
Disposable
attachDisposeAction
::
MonadIO
m
=>
ResourceManager
->
IO
(
Awaitable
()
)
->
m
Disposable
attachDisposeAction
_resourceManager
_action
=
liftIO
undefined
attachDisposeAction
resourceManager
action
=
do
disposable
<-
newDisposable
action
attachDisposable
resourceManager
disposable
pure
disposable
-- | Attaches a dispose action to a ResourceManager. It will automatically be run when the resource manager is disposed.
-- | Attaches a dispose action to a ResourceManager. It will automatically be run when the resource manager is disposed.
attachDisposeAction_
::
MonadIO
m
=>
ResourceManager
->
IO
(
Awaitable
()
)
->
m
()
attachDisposeAction_
::
MonadIO
m
=>
ResourceManager
->
IO
(
Awaitable
()
)
->
m
()
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Observable.hs
+
16
−
14
View file @
9e5b3c2b
...
@@ -81,24 +81,26 @@ class IsRetrievable v o => IsObservable v o | o -> v where
...
@@ -81,24 +81,26 @@ class IsRetrievable v o => IsObservable v o | o -> v where
-- | Observe until the callback returns `False`. The callback will also be unsubscribed when the `ResourceManager` is disposed.
-- | Observe until the callback returns `False`. The callback will also be unsubscribed when the `ResourceManager` is disposed.
observeWhile
::
(
IsObservable
v
o
,
HasResourceManager
m
)
=>
o
->
(
ObservableMessage
v
->
IO
Bool
)
->
m
Disposable
observeWhile
::
(
IsObservable
v
o
,
HasResourceManager
m
)
=>
o
->
(
ObservableMessage
v
->
IO
Bool
)
->
m
Disposable
observeWhile
observable
callback
=
do
observeWhile
observable
callback
=
do
disposeVar
<-
liftIO
$
newTVarIO
False
--
disposeVar <- liftIO $ newTVarIO False
innerDisposable
<-
liftIO
$
observe
observable
\
msg
->
do
--
innerDisposable <- liftIO $ observe observable \msg -> do
disposeRequested
<-
readTVarIO
disposeVar
--
disposeRequested <- readTVarIO disposeVar
unless
disposeRequested
do
--
unless disposeRequested do
continue
<-
callback
msg
--
continue <- callback msg
unless
continue
$
atomically
$
writeTVar
disposeVar
True
--
unless continue $ atomically $ writeTVar disposeVar True
-- Bind the disposable to the ResourceManager, to prevent leaks if the `async` is disposed
--
--
Bind the disposable to the ResourceManager, to prevent leaks if the `async` is disposed
disposable
<-
boundDisposable
$
dispose
innerDisposable
--
disposable <- boundDisposable $ dispose innerDisposable
task
<-
async
do
--
task <- async do
liftIO
$
atomically
do
--
liftIO $ atomically do
disposeRequested
<-
readTVar
disposeVar
--
disposeRequested <- readTVar disposeVar
unless
disposeRequested
retry
--
unless disposeRequested retry
liftIO
$
dispose
disposable
--
liftIO $ dispose disposable
pure
(
disposable
<>
(
toDisposable
task
))
--pure (disposable <> (toDisposable task))
undefined
-- TODO reimplement after ResouceManager API is changed
-- | Observe until the callback returns `False`. The callback will also be unsubscribed when the `ResourceManager` is disposed.
-- | Observe until the callback returns `False`. The callback will also be unsubscribed when the `ResourceManager` is disposed.
...
...
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