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
7ff04621
Commit
7ff04621
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add registerNewResource to handle a diposed resource manager
Co-authored-by:
Jan Beinke
<
git@janbeinke.com
>
parent
8ab59796
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/ResourceManager.hs
+14
-11
14 additions, 11 deletions
src/Quasar/ResourceManager.hs
with
14 additions
and
11 deletions
src/Quasar/ResourceManager.hs
+
14
−
11
View file @
7ff04621
...
...
@@ -2,6 +2,7 @@ module Quasar.ResourceManager (
-- * MonadResourceManager
MonadResourceManager
(
..
),
FailedToRegisterResource
,
registerNewResource
,
registerDisposable
,
registerDisposeAction
,
registerSimpleDisposeAction
,
...
...
@@ -136,6 +137,12 @@ registerDisposeAction disposeAction = mask_ $ registerDisposable =<< newDisposab
registerSimpleDisposeAction
::
MonadResourceManager
m
=>
IO
()
->
m
()
registerSimpleDisposeAction
disposeAction
=
registerDisposeAction
(
pure
()
<$
disposeAction
)
registerNewResource
::
(
IsDisposable
a
,
MonadResourceManager
m
)
=>
m
a
->
m
a
registerNewResource
action
=
mask_
do
afix
\
awaitable
->
do
registerDisposeAction
$
either
(
\
(
_
::
SomeException
)
->
mempty
)
dispose
=<<
try
(
await
awaitable
)
action
-- TODO rename to withResourceScope?
withSubResourceManagerM
::
MonadResourceManager
m
=>
m
a
->
m
a
...
...
@@ -278,20 +285,15 @@ instance IsResourceManager DefaultResourceManager where
entry
<-
newEntry
disposable
join
$
atomically
do
disposing
<-
readTVar
(
disposingVar
resourceManager
)
disposed
<-
readTVar
(
disposedVar
resourceManager
)
unless
dispos
ed
$
modifyTVar
(
entriesVar
resourceManager
)
(
|>
entry
)
unless
dispos
ing
$
modifyTVar
(
entriesVar
resourceManager
)
(
|>
entry
)
disposing
<-
readTVar
(
disposingVar
resourceManager
)
-- IO that is run after the STM transaction is completed
pure
$
(`
catchAll
`
throwToResourceManager
resourceManager
)
do
if
disposed
then
do
traceIO
"Attached a disposable to a disposed resource manager"
await
=<<
dispose
disposable
else
when
disposing
do
void
(
dispose
disposable
)
pure
do
-- IO that is run after the STM transaction is completed
when
disposing
$
throwM
FailedToRegisterResource
`
catchAll
`
throwToResourceManager
resourceManager
instance
IsDisposable
DefaultResourceManager
where
dispose
resourceManager
=
liftIO
$
mask_
do
...
...
@@ -406,6 +408,7 @@ freeGarbage resourceManager = go
entriesVar'
=
entriesVar
resourceManager
-- | 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
resourceManager
action
=
liftIO
$
mask_
$
do
...
...
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