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
3d786053
Commit
3d786053
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add TIOWorker
Co-authored-by:
Jan Beinke
<
git@janbeinke.com
>
parent
e378fea9
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
quasar.cabal
+1
-0
1 addition, 0 deletions
quasar.cabal
src/Quasar/Async/STMHelper.hs
+47
-0
47 additions, 0 deletions
src/Quasar/Async/STMHelper.hs
with
48 additions
and
0 deletions
quasar.cabal
+
1
−
0
View file @
3d786053
...
...
@@ -87,6 +87,7 @@ library
Quasar
Quasar.Async
Quasar.Async.Unmanaged
Quasar.Async.STMHelper
Quasar.Awaitable
Quasar.Disposable
Quasar.Exceptions
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Async/STMHelper.hs
0 → 100644
+
47
−
0
View file @
3d786053
module
Quasar.Async.STMHelper
(
TIOWorker
,
newTIOWorker
,
startTrivialIO
,
startTrivialIO_
,
)
where
import
Control.Concurrent
(
forkIO
)
import
Control.Concurrent.STM
import
Control.Exception
(
BlockedIndefinitelyOnSTM
)
import
Control.Monad.Catch
import
Quasar.Awaitable
import
Quasar.Exceptions
import
Quasar.Prelude
newtype
TIOWorker
=
TIOWorker
(
TMVar
(
IO
()
))
startTrivialIO
::
forall
a
.
TIOWorker
->
ExceptionChannel
->
IO
a
->
STM
(
Awaitable
a
)
startTrivialIO
(
TIOWorker
jobVar
)
exChan
fn
=
do
resultVar
<-
newAsyncVarSTM
putTMVar
jobVar
$
job
resultVar
pure
$
toAwaitable
resultVar
where
job
::
AsyncVar
a
->
IO
()
job
resultVar
=
do
try
fn
>>=
\
case
Left
ex
->
do
atomically
$
throwToExceptionChannel
exChan
ex
failAsyncVar_
resultVar
$
toException
$
AsyncException
ex
Right
result
->
putAsyncVar_
resultVar
result
startTrivialIO_
::
forall
a
.
TIOWorker
->
ExceptionChannel
->
IO
a
->
STM
()
startTrivialIO_
x
y
z
=
void
$
startTrivialIO
x
y
z
newTIOWorker
::
IO
TIOWorker
newTIOWorker
=
do
jobVar
<-
newEmptyTMVarIO
void
$
forkIO
$
handle
-- Relies on garbage collection to remove the thread when it is no longer needed
(
\
(
_
::
BlockedIndefinitelyOnSTM
)
->
pure
()
)
(
forever
$
join
$
atomically
$
takeTMVar
jobVar
)
pure
$
TIOWorker
jobVar
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