@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
81 lines (41 loc) • 1.43 kB
Markdown
---
lang: en
title: 'API docs: context.trywithfinally'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.trywithfinally.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [tryWithFinally](./context.trywithfinally.md)
## tryWithFinally() function
Try to run an action that returns a promise or a value
**Signature:**
```typescript
export declare function tryWithFinally<T>(action: () => ValueOrPromise<T>, finalAction: () => void): ValueOrPromise<T>;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
action
</td><td markdown="1">
() => [ValueOrPromise](./context.valueorpromise.md)<!-- --><T>
</td><td markdown="1">
A function that returns a promise or a value
</td></tr>
<tr><td markdown="1">
finalAction
</td><td markdown="1">
() => void
</td><td markdown="1">
A function to be called once the action is fulfilled or rejected (synchronously or asynchronously)
</td></tr>
</tbody></table>
**Returns:**
[ValueOrPromise](./context.valueorpromise.md)<!-- --><T>