Skip to content

Conversation

lhames
Copy link
Contributor

@lhames lhames commented Sep 5, 2025

make_scoped_exit takes a function object and returns an object that will run the given function object at destruction time (unless the scope-exit object's release method is called to disable it).

This can be useful when a function needs to conditionally perform some cleanup, but may exit along multiple pathways. E.g.

  // Allocate resource here.
  auto DoCleanup = make_scope_exit([]() {
    // release resource here.
  });

  // various conditional error return paths.
  if (...)
    return make_error<...>(...);

  // successful return: cancel cleanup.
  DoCleanup.release();
  return Error::success();

make_scoped_exit takes a function object and returns an object that will run
the given function object at destruction time (unless the scope-exit object's
`release` method is called to disable it).

This can be useful when a function needs to conditionally perform some
cleanup, but may exit along multiple pathways. E.g.

```
  // Allocate resource here.
  auto DoCleanup = make_scope_exit([]() {
    // release resource here.
  });

  // various conditional error return paths.
  if (...)
    return make_error<...>(...);

  // successful return: cancel cleanup.
  DoCleanup.release();
  return Error::success();
```
@lhames lhames merged commit aef11db into llvm:main Sep 5, 2025
10 checks passed
@lhames lhames deleted the orc-rt-add-make-scope-exit branch September 5, 2025 12:53
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

Successfully merging this pull request may close these issues.

1 participant