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
36dc2211
Commit
36dc2211
authored
2 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Update TOnce to use MonadSTM'
parent
90f5ebf2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quasar/src/Quasar/Utils/TOnce.hs
+6
-6
6 additions, 6 deletions
quasar/src/Quasar/Utils/TOnce.hs
with
6 additions
and
6 deletions
quasar/src/Quasar/Utils/TOnce.hs
+
6
−
6
View file @
36dc2211
...
@@ -20,14 +20,14 @@ newtype TOnce a b = TOnce (TVar (Either a b))
...
@@ -20,14 +20,14 @@ newtype TOnce a b = TOnce (TVar (Either a b))
instance
IsFuture
b
(
TOnce
a
b
)
where
instance
IsFuture
b
(
TOnce
a
b
)
where
toFuture
=
unsafeAwaitSTM
.
readTOnceResult
toFuture
=
unsafeAwaitSTM
.
readTOnceResult
newTOnce
::
a
->
STM
(
TOnce
a
b
)
newTOnce
::
MonadSTM'
r
t
m
=>
a
->
m
(
TOnce
a
b
)
newTOnce
initial
=
TOnce
<$>
newTVar
(
Left
initial
)
newTOnce
initial
=
TOnce
<$>
newTVar
(
Left
initial
)
newTOnceIO
::
a
->
IO
(
TOnce
a
b
)
newTOnceIO
::
MonadIO
m
=>
a
->
m
(
TOnce
a
b
)
newTOnceIO
initial
=
TOnce
<$>
newTVarIO
(
Left
initial
)
newTOnceIO
initial
=
TOnce
<$>
newTVarIO
(
Left
initial
)
mapFinalizeTOnce
::
TOnce
a
b
->
(
a
->
STM
b
)
->
STM
b
mapFinalizeTOnce
::
MonadSTM'
r
t
m
=>
TOnce
a
b
->
(
a
->
m
b
)
->
m
b
mapFinalizeTOnce
(
TOnce
var
)
fn
=
mapFinalizeTOnce
(
TOnce
var
)
fn
=
readTVar
var
>>=
\
case
readTVar
var
>>=
\
case
Left
initial
->
do
Left
initial
->
do
...
@@ -36,17 +36,17 @@ mapFinalizeTOnce (TOnce var) fn =
...
@@ -36,17 +36,17 @@ mapFinalizeTOnce (TOnce var) fn =
pure
final
pure
final
Right
final
->
pure
final
Right
final
->
pure
final
finalizeTOnce
::
TOnce
a
b
->
b
->
STM
()
finalizeTOnce
::
MonadSTM'
r
CanThrow
m
=>
TOnce
a
b
->
b
->
m
()
finalizeTOnce
(
TOnce
var
)
value
=
finalizeTOnce
(
TOnce
var
)
value
=
readTVar
var
>>=
\
case
readTVar
var
>>=
\
case
Left
_
->
writeTVar
var
(
Right
value
)
Left
_
->
writeTVar
var
(
Right
value
)
Right
_
->
throwSTM
TOnceAlreadyFinalized
Right
_
->
throwSTM
TOnceAlreadyFinalized
readTOnceState
::
TOnce
a
b
->
STM
(
Either
a
b
)
readTOnceState
::
MonadSTM'
r
t
m
=>
TOnce
a
b
->
m
(
Either
a
b
)
readTOnceState
(
TOnce
var
)
=
readTVar
var
readTOnceState
(
TOnce
var
)
=
readTVar
var
readTOnceResult
::
TOnce
a
b
->
STM
b
readTOnceResult
::
MonadSTM'
CanRetry
t
m
=>
TOnce
a
b
->
m
b
readTOnceResult
switch
=
readTOnceResult
switch
=
readTOnceState
switch
>>=
\
case
readTOnceState
switch
>>=
\
case
Right
final
->
pure
final
Right
final
->
pure
final
...
...
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