finally multimethod

Methods

finally(body:Fun, cleanup:Fun) Source: stdlib.ngs:1523
Run cleanup after successful execution of body or exception in body

Parameters

bodyMain code to execute
cleanupCleanup code to execute

Returns

Whatever body call returns

Example

finally(
  { while entry = c_readdir(d) { ... } },
  { ... c_closedir(d) ...}
)
# Alternative function call syntax:
finally()
  body => {
    while entry = c_readdir(d) {
      cb(Path(dirname / entry.d_name, subtype=subtype))
    }
  }
  cleanup => {
    r = c_closedir(d)
    r != 0 throws DirFail('Failed to close directory after listing').set('dirname', dirname)
  }