unregisterPipelineInternal :: PipelineId -> LambdaCubeEnv t -> IO ()
unregisterPipelineInternal i LambdaCubeEnv{..} = do
  pipelines <- readIORef lambdaEnvPipelines
  case M.lookup i pipelines of
    Nothing -> return ()
    Just PipelineInfo{..} -> do
      storages <- snd <$> readIORef lambdaEnvStorages
      let storagesToDispose = M.filterWithKey (\k _ -> isPipelineStorage i k) storages
      mapM_ LambdaCubeGL.disposeStorage $ storagesToDispose
      LambdaCubeGL.disposeRenderer pipeInfoRenderer
      atomicModifyIORef' lambdaEnvPipelines $ (, ()) . M.delete i
      atomicModifyIORef' lambdaEnvStorages $ \(n, m) -> ((n, M.filterWithKey (\k _ -> not $ isPipelineStorage i k) m), ())

-- | Getter of pipeline scheme
unregisterPipelineInternal :: PipelineId -> LambdaCubeEnv t -> IO ()
unregisterPipelineInternal i LambdaCubeEnv{..} = do
  pipelines <- readIORef lambdaEnvPipelines
  case M.lookup i pipelines of
    Nothing -> return ()
    Just PipelineInfo{..} -> do
      storages <- snd <$> readIORef lambdaEnvStorages
      let storagesToDispose = M.filterWithKey (\k _ -> isPipelineStorage i k) storages
      mapM_ LambdaCubeGL.disposeStorage $ storagesToDispose
      LambdaCubeGL.disposeRenderer pipeInfoRenderer
      atomicModifyIORef' lambdaEnvPipelines $ (, ()) . M.delete i
      atomicModifyIORef' lambdaEnvStorages $ \(n, m) -> ((n, M.filterWithKey (\k _ -> not $ isPipelineStorage i k) m), ())

-- | Getter of pipeline scheme
unregisterPipelineInternal i LambdaCubeEnv{..} = do
  pipelines <- readIORef lambdaEnvPipelines
  case M.lookup i pipelines of
    Nothing -> return ()
    Just PipelineInfo{..} -> do
      storages <- snd <$> readIORef lambdaEnvStorages
      let storagesToDispose = M.filterWithKey (\k _ -> isPipelineStorage i k) storages
      mapM_ LambdaCubeGL.disposeStorage $ storagesToDispose
      LambdaCubeGL.disposeRenderer pipeInfoRenderer
      atomicModifyIORef' lambdaEnvPipelines $ (, ()) . M.delete i
      atomicModifyIORef' lambdaEnvStorages $ \(n, m) -> ((n, M.filterWithKey (\k _ -> not $ isPipelineStorage i k) m), ())

-- | Getter of pipeline scheme