finishBuilding :: Handle -> AssetId -> Result -> IO ()
finishBuilding h aId res = do
    now <- getCurrentTime

    let diff (Building t0) = diffUTCTime now t0
        diff _             = fromIntegral (0 :: Int)

    adjustAssetRuntimeState h aId $ \ars -> ars
        { arsState = Completed (diff $ arsState ars)
        , arsResult = Just res
        }

    mbArs <- atomically $ do
        s <- readTVar (state h)
        return $ M.lookup aId (assets s)

    case mbArs of
        Nothing -> return ()
        Just ars -> case arsState ars of
            Completed td -> logMessage h aId $ "Build time: " ++ show td
            _ -> return ()


    -- Go through all reverse dependencies and mark them as dirty.
    rebuildReverseDependencies h aId
finishBuilding :: Handle -> AssetId -> Result -> IO ()
finishBuilding h aId res = do
    now <- getCurrentTime

    let diff (Building t0) = diffUTCTime now t0
        diff _             = fromIntegral (0 :: Int)

    adjustAssetRuntimeState h aId $ \ars -> ars
        { arsState = Completed (diff $ arsState ars)
        , arsResult = Just res
        }

    mbArs <- atomically $ do
        s <- readTVar (state h)
        return $ M.lookup aId (assets s)

    case mbArs of
        Nothing -> return ()
        Just ars -> case arsState ars of
            Completed td -> logMessage h aId $ "Build time: " ++ show td
            _ -> return ()


    -- Go through all reverse dependencies and mark them as dirty.
    rebuildReverseDependencies h aId
finishBuilding h aId res = do
    now <- getCurrentTime

    let diff (Building t0) = diffUTCTime now t0
        diff _             = fromIntegral (0 :: Int)

    adjustAssetRuntimeState h aId $ \ars -> ars
        { arsState = Completed (diff $ arsState ars)
        , arsResult = Just res
        }

    mbArs <- atomically $ do
        s <- readTVar (state h)
        return $ M.lookup aId (assets s)

    case mbArs of
        Nothing -> return ()
        Just ars -> case arsState ars of
            Completed td -> logMessage h aId $ "Build time: " ++ show td
            _ -> return ()


    -- Go through all reverse dependencies and mark them as dirty.
    rebuildReverseDependencies h aId