@loopback/docs
Version:
Documentation for LoopBack 4
36 lines (23 loc) • 1.14 kB
Markdown
---
lang: en
title: 'API docs: context.trywithfinally'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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
<b>Signature:</b>
```typescript
export declare function tryWithFinally<T>(action: () => ValueOrPromise<T>, finalAction: () => void): ValueOrPromise<T>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| action | () => [ValueOrPromise](./context.valueorpromise.md)<!-- --><T> | A function that returns a promise or a value |
| finalAction | () => void | A function to be called once the action is fulfilled or rejected (synchronously or asynchronously) |
<b>Returns:</b>
[ValueOrPromise](./context.valueorpromise.md)<!-- --><T>