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
5deae370
Commit
5deae370
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add instances to Awaitable (MonadThrow, MonadCatch and more)
parent
c364e76c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2399
passed
3 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Awaitable.hs
+20
-0
20 additions, 0 deletions
src/Quasar/Awaitable.hs
with
20 additions
and
0 deletions
src/Quasar/Awaitable.hs
+
20
−
0
View file @
5deae370
...
@@ -34,6 +34,7 @@ module Quasar.Awaitable (
...
@@ -34,6 +34,7 @@ module Quasar.Awaitable (
cacheAwaitableDefaultImplementation
,
cacheAwaitableDefaultImplementation
,
)
where
)
where
import
Control.Applicative
(
empty
)
import
Control.Concurrent.STM
import
Control.Concurrent.STM
import
Control.Monad.Catch
import
Control.Monad.Catch
import
Control.Monad.Reader
import
Control.Monad.Reader
...
@@ -93,6 +94,25 @@ instance Semigroup r => Semigroup (Awaitable r) where
...
@@ -93,6 +94,25 @@ instance Semigroup r => Semigroup (Awaitable r) where
instance
Monoid
r
=>
Monoid
(
Awaitable
r
)
where
instance
Monoid
r
=>
Monoid
(
Awaitable
r
)
where
mempty
=
pure
mempty
mempty
=
pure
mempty
instance
MonadThrow
Awaitable
where
throwM
=
failedAwaitable
.
toException
instance
MonadCatch
Awaitable
where
catch
awaitable
handler
=
toAwaitable
$
FnAwaitable
do
runAwaitable
awaitable
>>=
\
case
l
@
(
Left
ex
)
->
maybe
(
pure
l
)
(
runAwaitable
.
handler
)
$
fromException
ex
Right
value
->
pure
$
Right
value
instance
MonadFail
Awaitable
where
fail
=
throwM
.
userError
instance
Alternative
Awaitable
where
x
<|>
y
=
x
`
catchAll
`
const
y
empty
=
failedAwaitable
$
toException
$
userError
"empty"
instance
MonadPlus
Awaitable
newtype
FnAwaitable
r
=
FnAwaitable
(
forall
m
.
(
MonadQuerySTM
m
)
=>
m
(
Either
SomeException
r
))
newtype
FnAwaitable
r
=
FnAwaitable
(
forall
m
.
(
MonadQuerySTM
m
)
=>
m
(
Either
SomeException
r
))
...
...
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