Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cleanupTmpDir asyncronous (returning Aff) #1619

Open
Renegatto opened this issue May 15, 2024 · 0 comments
Open

Make cleanupTmpDir asyncronous (returning Aff) #1619

Renegatto opened this issue May 15, 2024 · 0 comments

Comments

@Renegatto
Copy link
Collaborator

Why

This will allow a caller to work with it more accurately, catching errors if needed.

Affected issues

It should partially fix #1580, to be precise it could allow fixing incomplete Plutip cluster cleanup after tests.

Calling cleanupTmpDir from startKupo' like this

  _ <- Aff.forkAff $ logErrorWhenLeft =<< try (cleanupTmpDir process workdir)

Would prevent any event handler error from killing the app before the full plutip cluster cleanup is done.

Implementation

cleanupTmpDir :: ManagedProcess -> FilePath -> Aff Unit
cleanupTmpDir (ManagedProcess _ child _) workingDir =
  Aff.makeAff \callback -> do
    isCancelled <- Ref.new false
    let
      cancel = void $ Ref.modify (const true) isCancelled 
    ChildProcess.onExit child \_ ->
      Ref.read isCancelled >>= flip unless do
        try (_rmdirSync workingDir) >>= callback
    pure $ Aff.effectCanceler cancel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant