Skip to content

Commit 2a38563

Browse files
committed
Thunk.Basic: forceMain: upd
1 parent 4fa4588 commit 2a38563

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/Nix/Thunk/Basic.hs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ instance (MonadBasicThunk m, MonadCatch m)
128128
-- Checks if resource is computed,
129129
-- if not - with locking evaluates the resource.
130130
forceMain
131-
:: ( MonadBasicThunk m
131+
:: forall v m
132+
. ( MonadBasicThunk m
132133
, MonadCatch m
133134
)
134135
=> NThunkF m v
135136
-> m v
136137
forceMain (Thunk tIdV tRefV tValRefV) =
137-
do
138-
v <- readRef tValRefV
139-
deferred pure computeW v
138+
deferred pure computeW =<< readRef tValRefV
140139
where
140+
computeW :: m v -> m v
141141
computeW vDefferred =
142142
do
143143
locked <- lock tRefV
@@ -149,16 +149,19 @@ forceMain (Thunk tIdV tRefV tValRefV) =
149149
unlockRef
150150
pure v
151151
)
152-
(not locked)
153-
154-
lockFailedV = throwM $ ThunkLoop $ show tIdV
155-
156-
bindFailedW (e :: SomeException) =
157-
do
158-
unlockRef
159-
throwM e
160-
161-
unlockRef = unlock tRefV
152+
$ not locked
153+
where
154+
lockFailedV :: m a
155+
lockFailedV = throwM $ ThunkLoop $ show tIdV
156+
157+
bindFailedW :: SomeException -> m b
158+
bindFailedW (e :: SomeException) =
159+
do
160+
unlockRef
161+
throwM e
162+
163+
unlockRef :: m Bool
164+
unlockRef = unlock tRefV
162165
{-# inline forceMain #-} -- it is big function, but internal, and look at its use.
163166

164167

0 commit comments

Comments
 (0)