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
af65ceea
Commit
af65ceea
authored
2 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Move newUnmanaged{IO,STM}Disposer to Disposer module
parent
6bd73fb0
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/Resources.hs
+0
-16
0 additions, 16 deletions
src/Quasar/Resources.hs
src/Quasar/Resources/Disposer.hs
+17
-0
17 additions, 0 deletions
src/Quasar/Resources/Disposer.hs
with
17 additions
and
16 deletions
src/Quasar/Resources.hs
+
0
−
16
View file @
af65ceea
...
...
@@ -43,26 +43,10 @@ module Quasar.Resources (
import
Control.Monad.Catch
import
Quasar.Future
import
Quasar.Async.Fork
import
Quasar.Async.STMHelper
import
Quasar.Exceptions
import
Quasar.MonadQuasar
import
Quasar.Prelude
import
Quasar.Resources.Disposer
import
Quasar.Utils.ShortIO
newUnmanagedIODisposer
::
IO
()
->
TIOWorker
->
ExceptionSink
->
STM
Disposer
-- TODO change TIOWorker behavior for spawning threads, so no `unsafeShortIO` is necessary
newUnmanagedIODisposer
fn
worker
exChan
=
newUnmanagedPrimitiveDisposer
(
unsafeShortIO
$
forkFuture
fn
exChan
)
worker
exChan
newUnmanagedSTMDisposer
::
STM
()
->
TIOWorker
->
ExceptionSink
->
STM
Disposer
newUnmanagedSTMDisposer
fn
worker
exChan
=
newUnmanagedPrimitiveDisposer
disposeFn
worker
exChan
where
disposeFn
::
ShortIO
(
Future
()
)
disposeFn
=
unsafeShortIO
$
atomically
$
-- Spawn a thread only if the transaction retries
(
pure
<$>
fn
)
`
orElse
`
forkAsyncSTM
(
atomically
fn
)
worker
exChan
registerResource
::
(
Resource
a
,
MonadQuasar
m
,
MonadSTM
m
)
=>
a
->
m
()
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Resources/Disposer.hs
+
17
−
0
View file @
af65ceea
...
...
@@ -7,6 +7,8 @@ module Quasar.Resources.Disposer (
disposeEventuallySTM
,
disposeEventuallySTM_
,
newUnmanagedPrimitiveDisposer
,
newUnmanagedIODisposer
,
newUnmanagedSTMDisposer
,
trivialDisposer
,
-- * Resource manager
...
...
@@ -23,6 +25,7 @@ import Data.HashMap.Strict (HashMap)
import
Data.HashMap.Strict
qualified
as
HM
import
Data.HashSet
(
HashSet
)
import
Data.HashSet
qualified
as
HashSet
import
Quasar.Async.Fork
import
Quasar.Async.STMHelper
import
Quasar.Future
import
Quasar.Exceptions
...
...
@@ -78,6 +81,20 @@ newUnmanagedPrimitiveDisposer fn worker exChan = toDisposer <$> do
key
<-
newUniqueSTM
FnDisposer
key
worker
exChan
<$>
newTOnce
fn
<*>
newFinalizers
newUnmanagedIODisposer
::
IO
()
->
TIOWorker
->
ExceptionSink
->
STM
Disposer
-- TODO change TIOWorker behavior for spawning threads, so no `unsafeShortIO` is necessary
newUnmanagedIODisposer
fn
worker
exChan
=
newUnmanagedPrimitiveDisposer
(
unsafeShortIO
$
forkFuture
fn
exChan
)
worker
exChan
newUnmanagedSTMDisposer
::
STM
()
->
TIOWorker
->
ExceptionSink
->
STM
Disposer
newUnmanagedSTMDisposer
fn
worker
exChan
=
newUnmanagedPrimitiveDisposer
disposeFn
worker
exChan
where
disposeFn
::
ShortIO
(
Future
()
)
disposeFn
=
unsafeShortIO
$
atomically
$
-- Spawn a thread only if the transaction retries
(
pure
<$>
fn
)
`
orElse
`
forkAsyncSTM
(
atomically
fn
)
worker
exChan
dispose
::
(
MonadIO
m
,
Resource
r
)
=>
r
->
m
()
dispose
resource
=
liftIO
$
await
=<<
atomically
(
disposeEventuallySTM
resource
)
...
...
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