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
887868b6
Commit
887868b6
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add constructor and accessors for Quasar fields
parent
a8910b57
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/Monad.hs
+47
-4
47 additions, 4 deletions
src/Quasar/Monad.hs
with
47 additions
and
4 deletions
src/Quasar/Monad.hs
+
47
−
4
View file @
887868b6
...
...
@@ -3,25 +3,58 @@ module Quasar.Monad (
newQuasar
,
MonadQuasar
(
..
),
askIOWorker
,
askExceptionChannel
,
askResourceManager
,
QuasarT
,
QuasarIO
,
QuasarSTM
,
)
where
import
Control.Concurrent.STM
import
Control.Monad.Reader
import
GHC.Records
(
HasField
(
..
))
import
Quasar.Async.STMHelper
import
Quasar.Exceptions
import
Quasar.Prelude
import
Quasar.Resources
import
Control.Monad.Reader
import
Quasar.Resources.Disposer
-- Invariant: the resource manager is disposed as soon as an exception is thrown to the channel
data
Quasar
=
Quasar
TIOWorker
ExceptionChannel
ResourceManager
instance
Resource
Quasar
where
getDisposer
(
Quasar
_
_
rm
)
=
getDisposer
rm
instance
HasField
"ioWorker"
Quasar
TIOWorker
where
getField
=
quasarIOWorker
instance
HasField
"exceptionChannel"
Quasar
ExceptionChannel
where
getField
=
quasarExceptionChannel
instance
HasField
"resourceManager"
Quasar
ResourceManager
where
getField
=
quasarResourceManager
quasarIOWorker
::
Quasar
->
TIOWorker
quasarIOWorker
(
Quasar
worker
_
_
)
=
worker
quasarExceptionChannel
::
Quasar
->
ExceptionChannel
quasarExceptionChannel
(
Quasar
_
exChan
_
)
=
exChan
quasarResourceManager
::
Quasar
->
ResourceManager
quasarResourceManager
(
Quasar
_
_
rm
)
=
rm
newQuasar
::
TIOWorker
->
ExceptionChannel
->
ResourceManager
->
STM
Quasar
newQuasar
=
undefined
newQuasar
worker
parentExChan
parentRM
=
do
rm
<-
newResourceManagerSTM
worker
parentExChan
attachResource
parentRM
rm
pure
$
Quasar
worker
(
ExceptionChannel
(
disposeOnException
rm
))
rm
where
disposeOnException
::
ResourceManager
->
SomeException
->
STM
()
disposeOnException
rm
ex
=
do
disposeEventuallySTM_
rm
throwToExceptionChannel
parentExChan
ex
class
Monad
m
=>
MonadQuasar
m
where
...
...
@@ -49,3 +82,13 @@ instance {-# OVERLAPPABLE #-} MonadQuasar m => MonadQuasar (ReaderT r m) where
runSTM
t
=
lift
(
runSTM
t
)
-- TODO MonadQuasar instances for StateT, WriterT, RWST, MaybeT, ...
askIOWorker
::
MonadQuasar
m
=>
m
TIOWorker
askIOWorker
=
quasarIOWorker
<$>
askQuasar
askExceptionChannel
::
MonadQuasar
m
=>
m
ExceptionChannel
askExceptionChannel
=
quasarExceptionChannel
<$>
askQuasar
askResourceManager
::
MonadQuasar
m
=>
m
ResourceManager
askResourceManager
=
quasarResourceManager
<$>
askQuasar
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