diff --git a/BUILD_SHA b/BUILD_SHA index 93b0e5c..f4bd7b8 100644 --- a/BUILD_SHA +++ b/BUILD_SHA @@ -1 +1 @@ -d3c9909935d9336f9c9848a07af4255c795a0915 +422f3f1317b2cc9d0a82c587968241f846137894 diff --git a/README.md b/README.md index 3e96bc9..1ff116b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P - [`ResultAsync.andThen` (method)](#resultasyncandthen-method) - [`ResultAsync.orElse` (method)](#resultasyncorelse-method) - [`ResultAsync.tap` (method)](#resultasynctap-method) + - [`ResultAsync.finally` (method)](#resultasyncfinally-method) - [`ResultAsync.match` (method)](#resultasyncmatch-method) - [`ResultAsync.combine` (static class method)](#resultasynccombine-static-class-method) - [`ResultAsync.combineWithAllErrors` (static class method)](#resultasynccombinewithallerrors-static-class-method) @@ -1093,10 +1094,42 @@ class ResultAsync { } ``` + + **Example:** See [`Result.tap` (method)](#resulttap-method) +[⬆️ Back to top](#toc) + +--- + +#### `ResultAsync.finally` (method) +Executes a cleanup function wether the is ok or error. This method is usefull to cleanup resources for async operations. +**Signature:** +```typescript +class ResultAsync { + finally(f: (value: T, error: E) => void): DisposableResultAsync {...} +} +``` + +**Example:** +```typescript +const fileHandle = await fs.open('foo.txt', 'w') + +const result + = await fromPromise(fileHandle.write('A new line of text'), String) + .finally(async () => { + console.info('Closing file handle') + await fileHandle.close() + }) + +if (result.isOk()) { + console.log(result.value) // == 'A new line of text' +} + +``` + [⬆️ Back to top](#toc) ---