Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
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
Container Registry
Model registry
Operate
Environments
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
qbar
Commits
893ca6c1
Commit
893ca6c1
authored
4 years ago
by
Mr. Snow Ball / projects
Browse files
Options
Downloads
Patches
Plain Diff
Refactor pipeBlockWithEvents: use BarIO and ExitBlock for producer
parent
85467aaf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/QBar/Blocks/Qubes.hs
+10
-8
10 additions, 8 deletions
src/QBar/Blocks/Qubes.hs
with
10 additions
and
8 deletions
src/QBar/Blocks/Qubes.hs
+
10
−
8
View file @
893ca6c1
...
...
@@ -5,6 +5,8 @@ import QBar.BlockOutput
import
QBar.Core
import
QBar.Qubes.AdminAPI
(
qubesUsageOfDefaultPool
,
qubesMonitorProperty
,
qubesGetProperty
,
qubesEvents
,
QubesPropertyInfo
(
..
))
import
Control.Concurrent.Async
import
Control.Monad.Reader
(
runReaderT
)
import
qualified
Data.ByteString.Lazy
as
BL
import
qualified
Data.Text.Lazy
as
T
import
Data.Text.Lazy.Encoding
(
decodeUtf8With
)
...
...
@@ -43,20 +45,20 @@ diskUsageQubesBlock = runPollBlock $ forever $ do
((
unit
,
factor
)
:
_
)
->
T
.
pack
(
show
$
size
`
div
`
factor
)
<>
unit
_
->
T
.
pack
(
show
size
)
<>
" bytes"
pipeBlockWithEvents
::
forall
a
.
Producer
a
(
P
.
SafeT
IO
)
()
->
(
Either
BlockEvent
a
->
BarIO
(
Maybe
BlockOutput
))
->
Block
pipeBlockWithEvents
::
forall
a
.
Producer
a
BarIO
ExitBlock
->
(
Either
BlockEvent
a
->
BarIO
(
Maybe
BlockOutput
))
->
Block
pipeBlockWithEvents
prod
block
=
do
bar
<-
askBar
(
output
,
input
)
<-
liftIO
$
spawn
$
newest
1
forkSafeEffect
$
prod
>->
P
.
map
Right
>->
toOutput
output
toExitBlock
$
fromInput
input
>->
forever
(
update
output
)
exitValue
<-
forkBarEffect
bar
$
prod
>->
P
.
map
Right
>->
forever
(
toOutput
output
)
fromInput
input
>->
forever
(
update
output
)
liftIO
$
wait
exitValue
where
fork
Safe
Effect
::
MonadIO
m
=>
Effect
(
P
.
SafeT
IO
)
()
->
m
(
)
fork
Safe
Effect
=
void
.
liftIO
.
forkIO
.
P
.
runSafeT
.
runEffect
fork
Bar
Effect
::
MonadIO
m
=>
Bar
->
Effect
BarIO
b
->
m
(
Async
b
)
fork
Bar
Effect
bar
=
liftIO
.
async
.
flip
runReaderT
bar
.
P
.
runSafeT
.
runEffect
forkEffect
::
MonadIO
m
=>
Effect
IO
()
->
m
()
forkEffect
=
void
.
liftIO
.
forkIO
.
runEffect
toExitBlock
=
fmap
(
const
ExitBlock
)
update
::
Output
(
Either
(
BlockOutput
,
BlockEvent
)
a
)
->
Pipe
(
Either
(
BlockOutput
,
BlockEvent
)
a
)
(
BlockState
,
BlockUpdateReason
)
BarIO
()
update
output
=
await
>>=
\
case
Right
prop
->
update'
$
Right
prop
...
...
@@ -74,7 +76,7 @@ pipeBlockWithEvents prod block = do
forkEffect
$
yield
(
Left
(
blockOutput
,
event
))
>->
toOutput
output
qubesMonitorPropertyBlock
::
BL
.
ByteString
->
Block
qubesMonitorPropertyBlock
name
=
pipeBlockWithEvents
(
qubesMonitorProperty
qubesEvents
name
)
handle
qubesMonitorPropertyBlock
name
=
pipeBlockWithEvents
(
qubesMonitorProperty
qubesEvents
name
>>
exitBlock
)
handle
where
handle
=
handle'
<=<
either
(
const
$
liftIO
$
qubesGetProperty
name
)
return
handle'
QubesPropertyInfo
{
propValue
,
propIsDefault
}
=
return
$
Just
$
mkBlockOutput
$
normalText
$
decode
propValue
<>
(
if
propIsDefault
then
" (D)"
else
""
)
...
...
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