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
c364e76c
Commit
c364e76c
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Fix disposing an empty resource manager after a delay
parent
2eb1a71d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/Disposable.hs
+7
-6
7 additions, 6 deletions
src/Quasar/Disposable.hs
test/Quasar/AwaitableSpec.hs
+3
-3
3 additions, 3 deletions
test/Quasar/AwaitableSpec.hs
with
10 additions
and
9 deletions
src/Quasar/Disposable.hs
+
7
−
6
View file @
c364e76c
...
@@ -255,19 +255,20 @@ collectGarbage resourceManager = go >> traceIO "gc: completed"
...
@@ -255,19 +255,20 @@ collectGarbage resourceManager = go >> traceIO "gc: completed"
go
::
IO
()
go
::
IO
()
go
=
do
go
=
do
traceIO
"gc: go"
traceIO
"gc: go"
(
snapshot
,
disposing
)
<-
atomically
$
do
snapshot
<-
atomically
$
readTVar
entriesVar'
snapshot
<-
readTVar
entriesVar'
disposing
<-
readTVar
(
disposingVar
resourceManager
)
pure
(
snapshot
,
disposing
)
let
listChanged
=
simpleAwaitable
$
do
let
listChanged
=
simpleAwaitable
do
newLength
<-
Seq
.
length
<$>
readTVar
entriesVar'
newLength
<-
Seq
.
length
<$>
readTVar
entriesVar'
when
(
newLength
==
Seq
.
length
snapshot
)
retry
when
(
newLength
==
Seq
.
length
snapshot
)
retry
isDisposing
=
simpleAwaitable
do
disposing
<-
readTVar
(
disposingVar
resourceManager
)
unless
disposing
retry
-- Wait for any entry to complete or until a new entry is added
-- Wait for any entry to complete or until a new entry is added
let
awaitables
=
(
toAwaitable
<$>
toList
snapshot
)
let
awaitables
=
(
toAwaitable
<$>
toList
snapshot
)
awaitIO
if
Quasar
.
Prelude
.
null
awaitables
awaitIO
if
Quasar
.
Prelude
.
null
awaitables
then
unless
disposing
$
listChanged
then
awaitAny2
listChanged
isDisposing
else
awaitAny
(
listChanged
:|
awaitables
)
else
awaitAny
(
listChanged
:|
awaitables
)
traceIO
"gc: change detected"
traceIO
"gc: change detected"
...
...
This diff is collapsed.
Click to expand it.
test/Quasar/AwaitableSpec.hs
+
3
−
3
View file @
c364e76c
...
@@ -30,7 +30,7 @@ spec = parallel $ do
...
@@ -30,7 +30,7 @@ spec = parallel $ do
awaitIO
avar
awaitIO
avar
it
"can be awaited
and
completed
later
"
$
do
it
"can be awaited
when
completed
asynchronously
"
$
do
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
void
$
forkIO
$
do
void
$
forkIO
$
do
threadDelay
100000
threadDelay
100000
...
@@ -86,7 +86,7 @@ spec = parallel $ do
...
@@ -86,7 +86,7 @@ spec = parallel $ do
putAsyncVar_
avar
()
putAsyncVar_
avar
()
withDefaultAsyncManager
(
id
<$>
await
avar
)
withDefaultAsyncManager
(
id
<$>
await
avar
)
x
it
"can fmap the result of an async that is completed later"
$
do
it
"can fmap the result of an async that is completed later"
$
do
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
void
$
forkIO
$
do
void
$
forkIO
$
do
threadDelay
100000
threadDelay
100000
...
@@ -98,7 +98,7 @@ spec = parallel $ do
...
@@ -98,7 +98,7 @@ spec = parallel $ do
putAsyncVar_
avar
()
putAsyncVar_
avar
()
withDefaultAsyncManager
(
await
avar
>>=
pure
)
withDefaultAsyncManager
(
await
avar
>>=
pure
)
x
it
"can bind the result of an async that is completed later"
$
do
it
"can bind the result of an async that is completed later"
$
do
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
avar
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
void
$
forkIO
$
do
void
$
forkIO
$
do
threadDelay
100000
threadDelay
100000
...
...
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