@@ -143,31 +143,31 @@ isDirty me = any (\(_,dep) -> resultBuilt me < resultChanged dep)
143
143
-- * If no dirty dependencies and we have evaluated the key previously, then we refresh it in the current thread.
144
144
-- This assumes that the implementation will be a lookup
145
145
-- * Otherwise, we spawn a new thread to refresh the dirty deps (if any) and the key itself
146
- refreshDeps :: KeySet -> Database -> Stack -> Key -> Result -> [KeySet ] -> AIO ( IO Result )
146
+ refreshDeps :: KeySet -> Database -> Stack -> Key -> Result -> [KeySet ] -> AIO Result
147
147
refreshDeps visited db stack key result = \ case
148
148
-- no more deps to refresh
149
- [] -> pure $ compute db stack key RunDependenciesSame (Just result)
149
+ [] -> liftIO $ compute db stack key RunDependenciesSame (Just result)
150
150
(dep: deps) -> do
151
151
let newVisited = dep <> visited
152
152
res <- builder db stack (toListKeySet (dep `differenceKeySet` visited))
153
153
case res of
154
154
Left res -> if isDirty result res
155
155
-- restart the computation if any of the deps are dirty
156
- then asyncWithCleanUp $ liftIO $ compute db stack key RunDependenciesChanged (Just result)
156
+ then liftIO $ compute db stack key RunDependenciesChanged (Just result)
157
157
-- else kick the rest of the deps
158
158
else refreshDeps newVisited db stack key result deps
159
- Right iores -> asyncWithCleanUp $ liftIO $ do
160
- res <- iores
159
+ Right iores -> do
160
+ res <- liftIO iores
161
161
if isDirty result res
162
- then compute db stack key RunDependenciesChanged (Just result)
163
- else join $ runAIO $ refreshDeps newVisited db stack key result deps
162
+ then liftIO $ compute db stack key RunDependenciesChanged (Just result)
163
+ else refreshDeps newVisited db stack key result deps
164
164
165
165
-- | Refresh a key:
166
166
refresh :: Database -> Stack -> Key -> Maybe Result -> AIO (IO Result )
167
167
-- refresh _ st k _ | traceShow ("refresh", st, k) False = undefined
168
168
refresh db stack key result = case (addStack key stack, result) of
169
169
(Left e, _) -> throw e
170
- (Right stack, Just me@ Result {resultDeps = ResultDeps deps}) -> refreshDeps mempty db stack key me (reverse deps)
170
+ (Right stack, Just me@ Result {resultDeps = ResultDeps deps}) -> asyncWithCleanUp $ refreshDeps mempty db stack key me (reverse deps)
171
171
(Right stack, _) ->
172
172
asyncWithCleanUp $ liftIO $ compute db stack key RunDependenciesChanged result
173
173
0 commit comments