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
ffc53b8a
Commit
ffc53b8a
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add constructor for FnDisposable
parent
7ffc5f7a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Awaitable.hs
+12
-9
12 additions, 9 deletions
src/Quasar/Awaitable.hs
with
12 additions
and
9 deletions
src/Quasar/Awaitable.hs
+
12
−
9
View file @
ffc53b8a
...
@@ -78,14 +78,14 @@ instance IsAwaitable r (Awaitable r) where
...
@@ -78,14 +78,14 @@ instance IsAwaitable r (Awaitable r) where
toAwaitable
=
id
toAwaitable
=
id
instance
Functor
Awaitable
where
instance
Functor
Awaitable
where
fmap
fn
(
Awaitable
x
)
=
toAwaitable
$
F
nAwaitable
$
fn
<<$>>
runAwaitable
x
fmap
fn
(
Awaitable
x
)
=
f
nAwaitable
$
fn
<<$>>
runAwaitable
x
instance
Applicative
Awaitable
where
instance
Applicative
Awaitable
where
pure
value
=
toAwaitable
$
F
nAwaitable
$
pure
(
Right
value
)
pure
value
=
f
nAwaitable
$
pure
(
Right
value
)
liftA2
fn
(
Awaitable
fx
)
(
Awaitable
fy
)
=
toAwaitable
$
F
nAwaitable
$
liftA2
(
liftA2
fn
)
(
runAwaitable
fx
)
(
runAwaitable
fy
)
liftA2
fn
(
Awaitable
fx
)
(
Awaitable
fy
)
=
f
nAwaitable
$
liftA2
(
liftA2
fn
)
(
runAwaitable
fx
)
(
runAwaitable
fy
)
instance
Monad
Awaitable
where
instance
Monad
Awaitable
where
(
Awaitable
fx
)
>>=
fn
=
toAwaitable
$
F
nAwaitable
$
do
(
Awaitable
fx
)
>>=
fn
=
f
nAwaitable
$
do
runAwaitable
fx
>>=
\
case
runAwaitable
fx
>>=
\
case
Left
ex
->
pure
$
Left
ex
Left
ex
->
pure
$
Left
ex
Right
x
->
runAwaitable
(
fn
x
)
Right
x
->
runAwaitable
(
fn
x
)
...
@@ -100,7 +100,7 @@ instance MonadThrow Awaitable where
...
@@ -100,7 +100,7 @@ instance MonadThrow Awaitable where
throwM
=
failedAwaitable
.
toException
throwM
=
failedAwaitable
.
toException
instance
MonadCatch
Awaitable
where
instance
MonadCatch
Awaitable
where
catch
awaitable
handler
=
toAwaitable
$
F
nAwaitable
do
catch
awaitable
handler
=
f
nAwaitable
do
runAwaitable
awaitable
>>=
\
case
runAwaitable
awaitable
>>=
\
case
l
@
(
Left
ex
)
->
maybe
(
pure
l
)
(
runAwaitable
.
handler
)
$
fromException
ex
l
@
(
Left
ex
)
->
maybe
(
pure
l
)
(
runAwaitable
.
handler
)
$
fromException
ex
Right
value
->
pure
$
Right
value
Right
value
->
pure
$
Right
value
...
@@ -123,6 +123,9 @@ instance IsAwaitable r (FnAwaitable r) where
...
@@ -123,6 +123,9 @@ instance IsAwaitable r (FnAwaitable r) where
runAwaitable
(
FnAwaitable
x
)
=
x
runAwaitable
(
FnAwaitable
x
)
=
x
cacheAwaitable
=
cacheAwaitableDefaultImplementation
cacheAwaitable
=
cacheAwaitableDefaultImplementation
fnAwaitable
::
(
forall
m
.
(
MonadQuerySTM
m
)
=>
m
(
Either
SomeException
r
))
->
Awaitable
r
fnAwaitable
fn
=
toAwaitable
$
FnAwaitable
fn
newtype
CompletedAwaitable
r
=
CompletedAwaitable
(
Either
SomeException
r
)
newtype
CompletedAwaitable
r
=
CompletedAwaitable
(
Either
SomeException
r
)
...
@@ -144,13 +147,13 @@ failedAwaitable = completedAwaitable . Left
...
@@ -144,13 +147,13 @@ failedAwaitable = completedAwaitable . Left
--
--
-- Use `retry` to signal that the awaitable is not yet completed and `throwM`/`throwSTM` to set the awaitable to failed.
-- Use `retry` to signal that the awaitable is not yet completed and `throwM`/`throwSTM` to set the awaitable to failed.
simpleAwaitable
::
STM
a
->
Awaitable
a
simpleAwaitable
::
STM
a
->
Awaitable
a
simpleAwaitable
query
=
toAwaitable
$
F
nAwaitable
$
querySTM
do
simpleAwaitable
query
=
f
nAwaitable
$
querySTM
do
(
Right
<$>
query
)
(
Right
<$>
query
)
`
catchAll
`
`
catchAll
`
\
ex
->
pure
(
Left
ex
)
\
ex
->
pure
(
Left
ex
)
mapAwaitable
::
IsAwaitable
i
a
=>
(
Either
SomeException
i
->
Either
SomeException
r
)
->
a
->
Awaitable
r
mapAwaitable
::
IsAwaitable
i
a
=>
(
Either
SomeException
i
->
Either
SomeException
r
)
->
a
->
Awaitable
r
mapAwaitable
fn
awaitable
=
toAwaitable
$
F
nAwaitable
$
fn
<$>
runAwaitable
awaitable
mapAwaitable
fn
awaitable
=
f
nAwaitable
$
fn
<$>
runAwaitable
awaitable
class
MonadThrow
m
=>
MonadQuerySTM
m
where
class
MonadThrow
m
=>
MonadQuerySTM
m
where
...
@@ -284,7 +287,7 @@ putAsyncVarEitherSTM_ var = void . putAsyncVarEitherSTM var
...
@@ -284,7 +287,7 @@ putAsyncVarEitherSTM_ var = void . putAsyncVarEitherSTM var
-- * Awaiting multiple asyncs
-- * Awaiting multiple asyncs
awaitEither
::
(
IsAwaitable
ra
a
,
IsAwaitable
rb
b
)
=>
a
->
b
->
Awaitable
(
Either
ra
rb
)
awaitEither
::
(
IsAwaitable
ra
a
,
IsAwaitable
rb
b
)
=>
a
->
b
->
Awaitable
(
Either
ra
rb
)
awaitEither
x
y
=
toAwaitable
$
F
nAwaitable
$
groupLefts
<$>
stepBoth
(
runAwaitable
x
)
(
runAwaitable
y
)
awaitEither
x
y
=
f
nAwaitable
$
groupLefts
<$>
stepBoth
(
runAwaitable
x
)
(
runAwaitable
y
)
where
where
stepBoth
::
MonadQuerySTM
m
=>
AwaitableStepM
ra
->
AwaitableStepM
rb
->
m
(
Either
ra
rb
)
stepBoth
::
MonadQuerySTM
m
=>
AwaitableStepM
ra
->
AwaitableStepM
rb
->
m
(
Either
ra
rb
)
stepBoth
(
AwaitableCompleted
resultX
)
_
=
pure
$
Left
resultX
stepBoth
(
AwaitableCompleted
resultX
)
_
=
pure
$
Left
resultX
...
@@ -298,7 +301,7 @@ awaitEither x y = toAwaitable $ FnAwaitable $ groupLefts <$> stepBoth (runAwaita
...
@@ -298,7 +301,7 @@ awaitEither x y = toAwaitable $ FnAwaitable $ groupLefts <$> stepBoth (runAwaita
awaitAny
::
IsAwaitable
r
a
=>
NonEmpty
a
->
Awaitable
r
awaitAny
::
IsAwaitable
r
a
=>
NonEmpty
a
->
Awaitable
r
awaitAny
xs
=
toAwaitable
$
F
nAwaitable
$
stepAll
Empty
Empty
$
runAwaitable
<$>
fromList
(
toList
xs
)
awaitAny
xs
=
f
nAwaitable
$
stepAll
Empty
Empty
$
runAwaitable
<$>
fromList
(
toList
xs
)
where
where
stepAll
stepAll
::
MonadQuerySTM
m
::
MonadQuerySTM
m
...
...
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