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
6111302e
Commit
6111302e
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Align function names
parent
51fc0af1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Quasar/Async/Fork.hs
+28
-20
28 additions, 20 deletions
src/Quasar/Async/Fork.hs
src/Quasar/Async/V2.hs
+16
-8
16 additions, 8 deletions
src/Quasar/Async/V2.hs
src/Quasar/Resources.hs
+1
-1
1 addition, 1 deletion
src/Quasar/Resources.hs
with
45 additions
and
29 deletions
src/Quasar/Async/Fork.hs
+
28
−
20
View file @
6111302e
module
Quasar.Async.Fork
(
module
Quasar.Async.Fork
(
-- * Forking with an asynchronous exception channel
-- * Forking with an asynchronous exception channel
-- ** STM
-- ** STM
fork
,
forkSTM
,
fork_
,
forkSTM_
,
forkWithUnmask
,
forkWithUnmaskSTM
,
forkWithUnmask_
,
forkWithUnmaskSTM_
,
forkAsyncSTM
,
forkAsyncWithUnmaskSTM
,
-- ** ShortIO
-- ** ShortIO
forkWithUnmaskShortIO
,
forkWithUnmaskShortIO
,
forkWithUnmaskShortIO_
,
forkWithUnmaskShortIO_
,
startIOThread
ShortIO
,
forkAsync
ShortIO
,
startIOThread
WithUnmaskShortIO
,
forkAsync
WithUnmaskShortIO
,
)
where
)
where
import
Control.Concurrent
(
ThreadId
)
import
Control.Concurrent
(
ThreadId
)
...
@@ -25,18 +27,25 @@ import Quasar.Utils.ShortIO
...
@@ -25,18 +27,25 @@ import Quasar.Utils.ShortIO
-- * Fork in STM (with ExceptionChannel)
-- * Fork in STM (with ExceptionChannel)
fork
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
fork
STM
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
fork
fn
=
forkWithUnmask
(
\
unmask
->
unmask
fn
)
fork
STM
fn
=
forkWithUnmask
STM
(
\
unmask
->
unmask
fn
)
fork_
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
()
fork
STM
_
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
()
fork_
fn
worker
exChan
=
void
$
fork
fn
worker
exChan
fork
STM
_
fn
worker
exChan
=
void
$
fork
STM
fn
worker
exChan
forkWithUnmask
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
forkWithUnmask
STM
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
forkWithUnmask
fn
worker
exChan
=
startShortIO
(
forkWithUnmaskShortIO
fn
exChan
)
worker
exChan
forkWithUnmask
STM
fn
worker
exChan
=
startShortIO
(
forkWithUnmaskShortIO
fn
exChan
)
worker
exChan
forkWithUnmask_
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
()
forkWithUnmaskSTM_
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
()
forkWithUnmask_
fn
worker
exChan
=
void
$
forkWithUnmask
fn
worker
exChan
forkWithUnmaskSTM_
fn
worker
exChan
=
void
$
forkWithUnmaskSTM
fn
worker
exChan
forkAsyncSTM
::
forall
a
.
IO
a
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
a
)
forkAsyncSTM
fn
worker
exChan
=
join
<$>
startShortIO
(
forkAsyncShortIO
fn
exChan
)
worker
exChan
forkAsyncWithUnmaskSTM
::
forall
a
.
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
a
)
forkAsyncWithUnmaskSTM
fn
worker
exChan
=
join
<$>
startShortIO
(
forkAsyncWithUnmaskShortIO
fn
exChan
)
worker
exChan
-- * Fork in ShortIO (with ExceptionChannel)
-- * Fork in ShortIO (with ExceptionChannel)
...
@@ -55,8 +64,11 @@ forkWithUnmaskShortIO_ fn exChan = void $ forkWithUnmaskShortIO fn exChan
...
@@ -55,8 +64,11 @@ forkWithUnmaskShortIO_ fn exChan = void $ forkWithUnmaskShortIO fn exChan
-- * Fork in ShortIO while collecting the result (with ExceptionChannel)
-- * Fork in ShortIO while collecting the result (with ExceptionChannel)
startIOThreadWithUnmaskShortIO
::
forall
a
.
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
ExceptionChannel
->
ShortIO
(
Awaitable
a
)
forkAsyncShortIO
::
forall
a
.
IO
a
->
ExceptionChannel
->
ShortIO
(
Awaitable
a
)
startIOThreadWithUnmaskShortIO
fn
exChan
=
do
forkAsyncShortIO
fn
=
forkAsyncWithUnmaskShortIO
(
$
fn
)
forkAsyncWithUnmaskShortIO
::
forall
a
.
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
ExceptionChannel
->
ShortIO
(
Awaitable
a
)
forkAsyncWithUnmaskShortIO
fn
exChan
=
do
resultVar
<-
newAsyncVarShortIO
resultVar
<-
newAsyncVarShortIO
forkWithUnmaskShortIO_
(
runAndPut
resultVar
)
exChan
forkWithUnmaskShortIO_
(
runAndPut
resultVar
)
exChan
pure
$
toAwaitable
resultVar
pure
$
toAwaitable
resultVar
...
@@ -72,7 +84,3 @@ startIOThreadWithUnmaskShortIO fn exChan = do
...
@@ -72,7 +84,3 @@ startIOThreadWithUnmaskShortIO fn exChan = do
failAsyncVar_
resultVar
(
AsyncException
ex
)
failAsyncVar_
resultVar
(
AsyncException
ex
)
Right
retVal
->
do
Right
retVal
->
do
putAsyncVar_
resultVar
retVal
putAsyncVar_
resultVar
retVal
startIOThreadShortIO
::
forall
a
.
IO
a
->
ExceptionChannel
->
ShortIO
(
Awaitable
a
)
startIOThreadShortIO
fn
=
startIOThreadWithUnmaskShortIO
(
$
fn
)
This diff is collapsed.
Click to expand it.
src/Quasar/Async/V2.hs
+
16
−
8
View file @
6111302e
module
Quasar.Async.V2
(
module
Quasar.Async.V2
(
Async
,
Async
,
async
,
async
,
async_
,
asyncWithUnmask
,
asyncWithUnmask
,
asyncWithUnmask_
,
-- ** Async exceptions
-- ** Async exceptions
CancelAsync
(
..
),
CancelAsync
(
..
),
...
@@ -11,8 +13,8 @@ module Quasar.Async.V2 (
...
@@ -11,8 +13,8 @@ module Quasar.Async.V2 (
isAsyncDisposed
,
isAsyncDisposed
,
-- ** Unmanaged variants
-- ** Unmanaged variants
unmanagedAsync
,
unmanagedAsync
STM
,
unmanagedAsyncWithUnmask
,
unmanagedAsyncWithUnmask
STM
,
)
where
)
where
import
Control.Concurrent
(
ThreadId
)
import
Control.Concurrent
(
ThreadId
)
...
@@ -38,15 +40,15 @@ instance IsAwaitable a (Async a) where
...
@@ -38,15 +40,15 @@ instance IsAwaitable a (Async a) where
toAwaitable
(
Async
awaitable
_
)
=
awaitable
toAwaitable
(
Async
awaitable
_
)
=
awaitable
unmanagedAsync
::
IO
a
->
TIOWorker
->
ExceptionChannel
->
STM
(
Async
a
)
unmanagedAsync
STM
::
IO
a
->
TIOWorker
->
ExceptionChannel
->
STM
(
Async
a
)
unmanagedAsync
fn
=
unmanagedAsyncWithUnmask
(
\
unmask
->
unmask
fn
)
unmanagedAsync
STM
fn
=
unmanagedAsyncWithUnmask
STM
(
\
unmask
->
unmask
fn
)
unmanagedAsyncWithUnmask
::
forall
a
.
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Async
a
)
unmanagedAsyncWithUnmask
STM
::
forall
a
.
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Async
a
)
unmanagedAsyncWithUnmask
fn
worker
exChan
=
do
unmanagedAsyncWithUnmask
STM
fn
worker
exChan
=
do
key
<-
newUniqueSTM
key
<-
newUniqueSTM
resultVar
<-
newAsyncVarSTM
resultVar
<-
newAsyncVarSTM
disposer
<-
mfix
\
disposer
->
do
disposer
<-
mfix
\
disposer
->
do
tidAwaitable
<-
forkWithUnmask
(
runAndPut
key
resultVar
disposer
)
worker
exChan
tidAwaitable
<-
forkWithUnmask
STM
(
runAndPut
key
resultVar
disposer
)
worker
exChan
newPrimitiveDisposer
(
disposeFn
key
resultVar
tidAwaitable
)
worker
exChan
newPrimitiveDisposer
(
disposeFn
key
resultVar
tidAwaitable
)
worker
exChan
pure
$
Async
(
toAwaitable
resultVar
)
disposer
pure
$
Async
(
toAwaitable
resultVar
)
disposer
where
where
...
@@ -78,6 +80,9 @@ unmanagedAsyncWithUnmask fn worker exChan = do
...
@@ -78,6 +80,9 @@ unmanagedAsyncWithUnmask fn worker exChan = do
async
::
MonadQuasar
m
=>
QuasarIO
a
->
m
(
Async
a
)
async
::
MonadQuasar
m
=>
QuasarIO
a
->
m
(
Async
a
)
async
fn
=
asyncWithUnmask
(
$
fn
)
async
fn
=
asyncWithUnmask
(
$
fn
)
async_
::
MonadQuasar
m
=>
QuasarIO
()
->
m
()
async_
fn
=
void
$
asyncWithUnmask
(
$
fn
)
asyncWithUnmask
::
MonadQuasar
m
=>
((
forall
b
.
QuasarIO
b
->
QuasarIO
b
)
->
QuasarIO
a
)
->
m
(
Async
a
)
asyncWithUnmask
::
MonadQuasar
m
=>
((
forall
b
.
QuasarIO
b
->
QuasarIO
b
)
->
QuasarIO
a
)
->
m
(
Async
a
)
asyncWithUnmask
fn
=
do
asyncWithUnmask
fn
=
do
quasar
<-
askQuasar
quasar
<-
askQuasar
...
@@ -85,7 +90,7 @@ asyncWithUnmask fn = do
...
@@ -85,7 +90,7 @@ asyncWithUnmask fn = do
exChan
<-
askExceptionChannel
exChan
<-
askExceptionChannel
rm
<-
askResourceManager
rm
<-
askResourceManager
runSTM
do
runSTM
do
as
<-
unmanagedAsyncWithUnmask
(
\
unmask
->
runReaderT
(
fn
(
liftUnmask
unmask
))
quasar
)
worker
exChan
as
<-
unmanagedAsyncWithUnmask
STM
(
\
unmask
->
runReaderT
(
fn
(
liftUnmask
unmask
))
quasar
)
worker
exChan
attachResource
rm
as
attachResource
rm
as
pure
as
pure
as
where
where
...
@@ -93,3 +98,6 @@ asyncWithUnmask fn = do
...
@@ -93,3 +98,6 @@ asyncWithUnmask fn = do
liftUnmask
unmask
innerAction
=
do
liftUnmask
unmask
innerAction
=
do
quasar
<-
askQuasar
quasar
<-
askQuasar
liftIO
$
unmask
$
runReaderT
innerAction
quasar
liftIO
$
unmask
$
runReaderT
innerAction
quasar
asyncWithUnmask_
::
MonadQuasar
m
=>
((
forall
b
.
QuasarIO
b
->
QuasarIO
b
)
->
QuasarIO
()
)
->
m
()
asyncWithUnmask_
fn
=
void
$
asyncWithUnmask
fn
This diff is collapsed.
Click to expand it.
src/Quasar/Resources.hs
+
1
−
1
View file @
6111302e
...
@@ -42,7 +42,7 @@ import Quasar.Resources.Disposer
...
@@ -42,7 +42,7 @@ import Quasar.Resources.Disposer
newIODisposer
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
Disposer
newIODisposer
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
Disposer
newIODisposer
fn
worker
exChan
=
newPrimitiveDisposer
(
startIOThread
ShortIO
fn
exChan
)
worker
exChan
newIODisposer
fn
worker
exChan
=
newPrimitiveDisposer
(
forkAsync
ShortIO
fn
exChan
)
worker
exChan
newSTMDisposer
::
STM
()
->
TIOWorker
->
ExceptionChannel
->
STM
Disposer
newSTMDisposer
::
STM
()
->
TIOWorker
->
ExceptionChannel
->
STM
Disposer
newSTMDisposer
fn
=
newIODisposer
(
atomically
fn
)
newSTMDisposer
fn
=
newIODisposer
(
atomically
fn
)
...
...
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