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
a0df9d46
Commit
a0df9d46
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add unmanaged async variants
Co-authored-by:
Jan Beinke
<
git@janbeinke.com
>
parent
778bfbec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2779
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Async.hs
+24
-5
24 additions, 5 deletions
src/Quasar/Async.hs
with
24 additions
and
5 deletions
src/Quasar/Async.hs
+
24
−
5
View file @
a0df9d46
module
Quasar.Async
(
Async
,
Async
(
..
)
,
async
,
async_
,
asyncWithUnmask
,
...
...
@@ -15,11 +15,16 @@ module Quasar.Async (
-- ** IO variant
async'
,
asyncWithUnmask'
,
-- ** Unmanaged variants
unmanagedAsync
,
unmanagedAsyncWithUnmask
,
)
where
import
Control.Concurrent
(
ThreadId
)
import
Control.Monad.Catch
import
Quasar.Async.Fork
import
Quasar.Async.STMHelper
import
Quasar.Future
import
Quasar.Exceptions
import
Quasar.MonadQuasar
...
...
@@ -63,17 +68,31 @@ async' fn = asyncWithUnmask' ($ fn)
asyncWithUnmask'
::
forall
a
m
.
(
MonadQuasar
m
,
MonadIO
m
)
=>
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
m
(
Async
a
)
asyncWithUnmask'
fn
=
liftQuasarIO
do
exChan
<-
askExceptionSink
worker
<-
askIOWorker
exSink
<-
askExceptionSink
spawnAsync
registerResourceIO
worker
exSink
fn
unmanagedAsync
::
forall
a
m
.
MonadIO
m
=>
TIOWorker
->
ExceptionSink
->
IO
a
->
m
(
Async
a
)
unmanagedAsync
worker
exSink
fn
=
liftIO
$
unmanagedAsyncWithUnmask
worker
exSink
(
$
fn
)
unmanagedAsyncWithUnmask
::
forall
a
m
.
MonadIO
m
=>
TIOWorker
->
ExceptionSink
->
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
m
(
Async
a
)
unmanagedAsyncWithUnmask
worker
exSink
fn
=
liftIO
$
spawnAsync
(
\
_
->
pure
()
)
worker
exSink
fn
spawnAsync
::
forall
a
m
.
(
MonadIO
m
,
MonadMask
m
)
=>
(
Disposer
->
m
()
)
->
TIOWorker
->
ExceptionSink
->
((
forall
b
.
IO
b
->
IO
b
)
->
IO
a
)
->
m
(
Async
a
)
spawnAsync
registerDisposerFn
worker
exSink
fn
=
do
key
<-
liftIO
newUnique
resultVar
<-
newPromise
afixExtra
\
threadIdFuture
->
mask_
do
-- Disposer is created first to ensure the resource can be safely attached
disposer
<-
registerDisposeActionIO
(
disposeFn
key
resultVar
threadIdFuture
)
disposer
<-
atomically
$
newUnmanagedIODisposer
(
disposeFn
key
resultVar
threadIdFuture
)
worker
exSink
registerDisposerFn
disposer
threadId
<-
liftIO
$
forkWithUnmask
(
runAndPut
ex
Chan
key
resultVar
disposer
)
ex
Chan
threadId
<-
liftIO
$
forkWithUnmask
(
runAndPut
ex
Sink
key
resultVar
disposer
)
ex
Sink
pure
(
Async
(
toFuture
resultVar
)
disposer
,
threadId
)
where
...
...
@@ -94,7 +113,7 @@ asyncWithUnmask' fn = liftQuasarIO do
disposeEventuallyIO_
disposer
disposeFn
::
Unique
->
Promise
a
->
Future
ThreadId
->
IO
()
disposeFn
key
resultVar
threadIdFuture
=
do
--
Should not block or
f
a
il
(unless the TIOWorker is broken)
--
ThreadId future will be
fil
led by afix
threadId
<-
await
threadIdFuture
throwTo
threadId
(
CancelAsync
key
)
-- Disposing is considered complete once a result (i.e. success or failure) has been stored
...
...
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