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
758a4bcf
Commit
758a4bcf
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Restrict types on awaitable helpers to fix type inference
parent
f192a2b4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2566
passed
3 years ago
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Quasar/Awaitable.hs
+5
-5
5 additions, 5 deletions
src/Quasar/Awaitable.hs
src/Quasar/Timer.hs
+1
-1
1 addition, 1 deletion
src/Quasar/Timer.hs
test/Quasar/AwaitableSpec.hs
+2
-2
2 additions, 2 deletions
test/Quasar/AwaitableSpec.hs
with
8 additions
and
8 deletions
src/Quasar/Awaitable.hs
+
5
−
5
View file @
758a4bcf
...
@@ -431,7 +431,7 @@ afix_ = void . afix
...
@@ -431,7 +431,7 @@ afix_ = void . afix
-- | Completes as soon as either awaitable completes.
-- | Completes as soon as either awaitable completes.
awaitEither
::
(
IsAwaitable
ra
a
,
IsAwaitable
rb
b
,
MonadAwait
m
)
=>
a
->
b
->
m
(
Either
ra
rb
)
awaitEither
::
MonadAwait
m
=>
Awaitable
ra
->
Awaitable
r
b
->
m
(
Either
ra
rb
)
awaitEither
x
y
=
mkMonadicAwaitable
$
stepBoth
(
runAwaitable
x
)
(
runAwaitable
y
)
awaitEither
x
y
=
mkMonadicAwaitable
$
stepBoth
(
runAwaitable
x
)
(
runAwaitable
y
)
where
where
stepBoth
::
MonadAwait
m
=>
AwaitableStepM
ra
->
AwaitableStepM
rb
->
m
(
Either
ra
rb
)
stepBoth
::
MonadAwait
m
=>
AwaitableStepM
ra
->
AwaitableStepM
rb
->
m
(
Either
ra
rb
)
...
@@ -451,8 +451,8 @@ eitherSTM x y = fmap Left x `orElse` fmap Right y
...
@@ -451,8 +451,8 @@ eitherSTM x y = fmap Left x `orElse` fmap Right y
-- Completes as soon as any awaitable in the list is completed and then returns the left-most completed result
-- Completes as soon as any awaitable in the list is completed and then returns the left-most completed result
-- (or exception).
-- (or exception).
awaitAny
::
(
IsAwaitable
r
a
,
MonadAwait
m
)
=>
NonEmpty
a
->
m
r
awaitAny
::
MonadAwait
m
=>
[
Awaitable
r
]
->
m
r
awaitAny
xs
=
mkMonadicAwaitable
$
stepAll
Empty
Empty
$
runAwaitable
<$>
fromList
(
toList
xs
)
awaitAny
xs
=
mkMonadicAwaitable
$
stepAll
Empty
Empty
$
runAwaitable
<$>
fromList
xs
where
where
stepAll
stepAll
::
MonadAwait
m
::
MonadAwait
m
...
@@ -477,5 +477,5 @@ anySTM (x :| xs) = x `orElse` maybe retry anySTM (nonEmpty xs)
...
@@ -477,5 +477,5 @@ anySTM (x :| xs) = x `orElse` maybe retry anySTM (nonEmpty xs)
-- | Like `awaitAny` with two awaitables.
-- | Like `awaitAny` with two awaitables.
awaitAny2
::
(
IsAwaitable
r
a
,
IsAwaitable
r
b
,
MonadAwait
m
)
=>
a
->
b
->
m
r
awaitAny2
::
MonadAwait
m
=>
Awaitable
r
->
Awaitable
r
->
m
r
awaitAny2
x
y
=
awaitAny
(
toAwaitable
x
:|
[
toAwaitable
y
]
)
awaitAny2
x
y
=
awaitAny
[
toAwaitable
x
,
toAwaitable
y
]
This diff is collapsed.
Click to expand it.
src/Quasar/Timer.hs
+
1
−
1
View file @
758a4bcf
...
@@ -120,7 +120,7 @@ startSchedulerThread scheduler = toDisposable <$> unmanagedAsync (schedulerThrea
...
@@ -120,7 +120,7 @@ startSchedulerThread scheduler = toDisposable <$> unmanagedAsync (schedulerThrea
wait
::
Timer
->
Int
->
IO
()
wait
::
Timer
->
Int
->
IO
()
wait
nextTimer
microseconds
=
do
wait
nextTimer
microseconds
=
do
delay
<-
newUnmanagedDelay
microseconds
delay
<-
newUnmanagedDelay
microseconds
awaitAny2
delay
nextTimerChanged
awaitAny2
(
await
delay
)
nextTimerChanged
dispose
delay
dispose
delay
where
where
nextTimerChanged
::
Awaitable
()
nextTimerChanged
::
Awaitable
()
...
...
This diff is collapsed.
Click to expand it.
test/Quasar/AwaitableSpec.hs
+
2
−
2
View file @
758a4bcf
...
@@ -53,7 +53,7 @@ spec = parallel $ do
...
@@ -53,7 +53,7 @@ spec = parallel $ do
void
$
forkIO
$
do
void
$
forkIO
$
do
threadDelay
100000
threadDelay
100000
putAsyncVar_
avar1
()
putAsyncVar_
avar1
()
awaitAny2
avar1
avar2
awaitAny2
(
await
avar1
)
(
await
avar2
)
it
"can be completed later by the second parameter"
$
do
it
"can be completed later by the second parameter"
$
do
avar1
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
avar1
<-
newAsyncVar
::
IO
(
AsyncVar
()
)
...
@@ -61,7 +61,7 @@ spec = parallel $ do
...
@@ -61,7 +61,7 @@ spec = parallel $ do
void
$
forkIO
$
do
void
$
forkIO
$
do
threadDelay
100000
threadDelay
100000
putAsyncVar_
avar2
()
putAsyncVar_
avar2
()
awaitAny2
avar1
avar2
awaitAny2
(
await
avar1
)
(
await
avar2
)
describe
"cacheAwaitable"
do
describe
"cacheAwaitable"
do
it
"can cache an awaitable"
$
io
do
it
"can cache an awaitable"
$
io
do
...
...
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