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
f59ef367
Commit
f59ef367
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Remove CancellationToken
parent
1d10e90e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/Core.hs
+0
-45
0 additions, 45 deletions
src/Quasar/Core.hs
test/Quasar/AsyncSpec.hs
+0
-9
0 additions, 9 deletions
test/Quasar/AsyncSpec.hs
with
0 additions
and
54 deletions
src/Quasar/Core.hs
+
0
−
45
View file @
f59ef367
...
...
@@ -5,9 +5,6 @@ module Quasar.Core (
await
,
runAsyncIO
,
awaitResult
,
-- * Cancellation
withCancellationToken
,
)
where
import
Control.Concurrent
(
forkIOWithUnmask
)
...
...
@@ -165,45 +162,3 @@ peekEitherSTM x y =
Just
(
Left
ex
)
->
pure
(
Just
(
Left
ex
))
Just
(
Right
r
)
->
pure
(
Just
(
Right
(
Right
r
)))
Nothing
->
pure
Nothing
-- * Cancellation
newtype
CancellationToken
=
CancellationToken
(
AsyncVar
Void
)
instance
IsAwaitable
Void
CancellationToken
where
toAwaitable
(
CancellationToken
var
)
=
toAwaitable
var
newCancellationToken
::
IO
CancellationToken
newCancellationToken
=
CancellationToken
<$>
newAsyncVar
cancel
::
Exception
e
=>
CancellationToken
->
e
->
IO
()
cancel
(
CancellationToken
var
)
=
failAsyncVar_
var
.
toException
isCancellationRequested
::
CancellationToken
->
IO
Bool
isCancellationRequested
(
CancellationToken
var
)
=
isJust
<$>
peekAwaitable
var
cancellationState
::
CancellationToken
->
IO
(
Maybe
SomeException
)
cancellationState
(
CancellationToken
var
)
=
(
either
Just
(
const
Nothing
)
=<<
)
<$>
peekAwaitable
var
throwIfCancellationRequested
::
CancellationToken
->
IO
()
throwIfCancellationRequested
(
CancellationToken
var
)
=
peekAwaitable
var
>>=
\
case
Just
(
Left
ex
)
->
throwIO
ex
_
->
pure
()
awaitUnlessCancellationRequested
::
IsAwaitable
a
b
=>
CancellationToken
->
b
->
AsyncIO
a
awaitUnlessCancellationRequested
cancellationToken
=
fmap
(
either
absurd
id
)
.
awaitEither
cancellationToken
.
toAwaitable
withCancellationToken
::
(
CancellationToken
->
IO
a
)
->
IO
a
withCancellationToken
action
=
do
cancellationToken
<-
newCancellationToken
resultMVar
::
MVar
(
Either
SomeException
a
)
<-
newEmptyMVar
uninterruptibleMask
$
\
unmask
->
do
void
$
forkIOWithUnmask
$
\
threadUnmask
->
do
putMVar
resultMVar
=<<
try
(
threadUnmask
(
action
cancellationToken
))
-- TODO test if it is better to run readMVar recursively or to keep it uninterruptible
either
throwIO
pure
=<<
(
unmask
(
readMVar
resultMVar
)
`
catchAll
`
(
\
ex
->
cancel
cancellationToken
ex
>>
readMVar
resultMVar
))
This diff is collapsed.
Click to expand it.
test/Quasar/AsyncSpec.hs
+
0
−
9
View file @
f59ef367
...
...
@@ -69,12 +69,3 @@ spec = parallel $ do
-- Use bind to create an AsyncIOPlumbing, which is the interesting case that uses `uninterruptibleMask` when run
await
never
>>=
pure
result
`
shouldBe
`
Nothing
describe
"CancellationToken"
$
do
it
"propagates outer exceptions to the cancellation token"
$
do
result
<-
timeout
100000
$
withCancellationToken
(
runAsyncIO
.
await
)
result
`
shouldBe
`
Nothing
it
"can return a value after cancellation"
$
do
result
<-
timeout
100000
$
withCancellationToken
(
fmap
(
either
(
const
True
)
(
const
False
))
.
atomically
.
awaitSTM
)
result
`
shouldBe
`
Just
True
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