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
jktr
qbar
Commits
78cb0eea
Commit
78cb0eea
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Transform BarIO using SafeT
parent
c6a549a3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
package.yaml
+1
-0
1 addition, 0 deletions
package.yaml
src/QBar/Core.hs
+17
-13
17 additions, 13 deletions
src/QBar/Core.hs
src/QBar/Server.hs
+2
-3
2 additions, 3 deletions
src/QBar/Server.hs
with
20 additions
and
16 deletions
package.yaml
+
1
−
0
View file @
78cb0eea
...
...
@@ -38,6 +38,7 @@ dependencies:
-
pipes-concurrency
-
pipes-network
-
pipes-parse
-
pipes-safe
-
stm
-
text
-
time
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Core.hs
+
17
−
13
View file @
78cb0eea
...
...
@@ -7,7 +7,7 @@ import QBar.BlockText
import
Control.Exception
(
catch
,
finally
,
IOException
)
import
Control.Monad
(
forever
)
import
Control.Monad.Reader
(
ReaderT
,
runReaderT
,
ask
,
asks
)
import
Control.Monad.Reader
(
ReaderT
,
runReaderT
,
ask
)
import
Control.Concurrent
(
threadDelay
)
import
Control.Concurrent.Async
import
Control.Concurrent.Event
as
Event
...
...
@@ -22,6 +22,7 @@ import qualified Data.Text.Lazy.Encoding as E
import
qualified
Data.Text.Lazy.IO
as
TIO
import
Pipes
import
Pipes.Concurrent
import
Pipes.Safe
(
SafeT
,
runSafeT
)
import
qualified
Pipes.Prelude
as
PP
import
System.Exit
import
System.IO
...
...
@@ -71,7 +72,7 @@ instance IsBlockMode CachedMode where
exitBlock
=
return
CachedMode
type
BarIO
=
ReaderT
Bar
IO
type
BarIO
=
SafeT
(
ReaderT
Bar
IO
)
data
Bar
=
Bar
{
requestBarUpdate
::
IO
()
,
...
...
@@ -89,7 +90,10 @@ type BarUpdateEvent = Event.Event
runBarIO
::
Bar
->
BarIO
r
->
IO
r
runBarIO
bar
action
=
runReaderT
action
bar
runBarIO
bar
action
=
runReaderT
(
runSafeT
action
)
bar
askBar
::
BarIO
Bar
askBar
=
lift
ask
createBlock
::
BlockText
->
BlockOutput
createBlock
text
=
BlockOutput
...
...
@@ -153,7 +157,7 @@ sharedInterval seconds = do
liftIO
$
threadDelay
$
seconds
*
1000000
-- Updates all client blocks
-- If send returns 'False' the clients mailbox has been closed, so it is removed
bar
<-
ask
bar
<-
ask
Bar
liftIO
$
modifyMVar_
clientsMVar
$
fmap
catMaybes
.
mapConcurrently
(
\
r
->
runBarIO
bar
$
runAndFilterClient
r
)
-- Then update the bar
updateBar
...
...
@@ -168,9 +172,9 @@ sharedInterval seconds = do
return
$
if
result
then
Just
client
else
Nothing
runClient
::
(
MVar
PullBlock
,
Output
(
Maybe
BlockOutput
))
->
BarIO
Bool
runClient
(
blockProducerMVar
,
output
)
=
do
bar
<-
ask
bar
<-
ask
Bar
liftIO
$
modifyMVar
blockProducerMVar
$
\
blockProducer
->
do
result
<-
runReaderT
(
next
blockProducer
)
bar
result
<-
runReaderT
(
runSafeT
$
next
blockProducer
)
bar
case
result
of
Left
_
->
return
(
exitBlock
,
False
)
Right
(
blockOutput
,
blockProducer'
)
->
do
...
...
@@ -237,9 +241,9 @@ startPersistentBlockScript :: FilePath -> CachedBlock
-- This is only using 'CachedBlock' because the code was already written and tested
-- This could probably be massively simplified by using the new 'pushBlock'
startPersistentBlockScript
path
=
do
bar
<-
lift
ask
bar
<-
lift
ask
Bar
do
(
output
,
input
,
seal
)
<-
liftIO
$
spawn'
$
latest
$
Just
emptyBlock
(
output
,
input
,
seal
)
<-
liftIO
$
spawn'
$
latest
$
Nothing
initialDataEvent
<-
liftIO
Event
.
new
task
<-
liftIO
$
async
$
do
let
processConfig
=
setStdin
closed
$
setStdout
createPipe
$
shell
path
...
...
@@ -275,19 +279,19 @@ startPersistentBlockScript path = do
addBlock
::
IsBlock
a
=>
a
->
BarIO
()
addBlock
block
=
do
newBlockChan'
<-
asks
newBlockChan
newBlockChan'
<-
newBlockChan
<$>
askBar
liftIO
$
atomically
$
writeTChan
newBlockChan'
$
toCachedBlock
block
updateBar
::
BarIO
()
updateBar
=
liftIO
=<<
asks
requestBarUpdate
updateBar
=
liftIO
=<<
requestBarUpdate
<$>
askBar
updateBar'
::
Bar
->
IO
()
updateBar'
=
run
ReaderT
updateBar
updateBar'
bar
=
run
BarIO
bar
updateBar
barAsync
::
BarIO
a
->
BarIO
(
Async
a
)
barAsync
action
=
do
bar
<-
ask
lift
$
async
$
run
ReaderT
action
bar
bar
<-
ask
Bar
lift
IO
$
async
$
run
BarIO
bar
action
cachePushBlock
::
PushBlock
->
CachedBlock
cachePushBlock
pushBlock
=
lift
(
next
pushBlock
)
>>=
either
(
const
exitBlock
)
withInitialBlock
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Server.hs
+
2
−
3
View file @
78cb0eea
...
...
@@ -9,7 +9,6 @@ import QBar.BlockText
import
QBar.Themes
import
Control.Monad
(
forever
,
when
,
unless
)
import
Control.Monad.Reader
(
ask
)
import
Control.Monad.STM
(
atomically
)
import
Control.Concurrent
(
threadDelay
,
forkFinally
)
import
Control.Concurrent.Async
...
...
@@ -138,7 +137,7 @@ createBarUpdateChannel = do
handleStdin
::
MainOptions
->
IORef
[(
T
.
Text
,
Click
->
BarIO
()
)]
->
BarIO
()
handleStdin
options
actionListIORef
=
do
bar
<-
ask
bar
<-
ask
Bar
liftIO
$
forever
$
do
line
<-
BSSC8
.
hGetLine
stdin
...
...
@@ -169,7 +168,7 @@ handleStdin options actionListIORef = do
installSignalHandlers
::
BarIO
()
installSignalHandlers
=
do
bar
<-
ask
bar
<-
ask
Bar
liftIO
$
void
$
installHandler
sigCONT
(
Catch
(
sigContAction
bar
))
Nothing
where
sigContAction
::
Bar
->
IO
()
...
...
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