checkpointEvery :: Int -> Journal a u -> STM (Journal a u)
checkpointEvery updateCount (Journal get updates record) = tweak <$> newTVar 0 where
  tweak count =
    let
      record' = writeTVar count (0 :: Int) >> record
      append' vnow u = do
        done <- modifyTVar' count (1+) >> append updates vnow u
        count' <- readTVar count
        case count' of
          _ | count' >= updateCount -> record'
            | otherwise -> pure done
    in Journal get (Updates (flush updates) append') record'
checkpointEvery :: Int -> Journal a u -> STM (Journal a u)
checkpointEvery updateCount (Journal get updates record) = tweak <$> newTVar 0 where
  tweak count =
    let
      record' = writeTVar count (0 :: Int) >> record
      append' vnow u = do
        done <- modifyTVar' count (1+) >> append updates vnow u
        count' <- readTVar count
        case count' of
          _ | count' >= updateCount -> record'
            | otherwise -> pure done
    in Journal get (Updates (flush updates) append') record'
checkpointEvery updateCount (Journal get updates record) = tweak <$> newTVar 0 where
  tweak count =
    let
      record' = writeTVar count (0 :: Int) >> record
      append' vnow u = do
        done <- modifyTVar' count (1+) >> append updates vnow u
        count' <- readTVar count
        case count' of
          _ | count' >= updateCount -> record'
            | otherwise -> pure done
    in Journal get (Updates (flush updates) append') record'