File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ describe('InvocationContext', () => {
60
60
expect ( invocationCtxForCheckName . invokeTargetMethod ( ) ) . to . eql ( true ) ;
61
61
} ) ;
62
62
63
+ it ( 'does not close when an interceptor is in processing' , ( ) => {
64
+ const result = invocationCtxForGreet . invokeTargetMethod ( ) ;
65
+ expect ( invocationCtxForGreet . isBound ( 'abc' ) ) ;
66
+ return result ;
67
+ } ) ;
68
+
63
69
class MyController {
64
70
static checkName ( name : string ) {
65
71
const firstLetter = name . substring ( 0 , 1 ) ;
@@ -73,6 +79,7 @@ describe('InvocationContext', () => {
73
79
74
80
function givenContext ( ) {
75
81
ctx = new Context ( ) ;
82
+ ctx . bind ( 'abc' ) . to ( 'xyz' ) ;
76
83
}
77
84
78
85
function givenInvocationContext ( ) {
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ import {filterByTag} from './binding-filter';
18
18
import { BindingAddress } from './binding-key' ;
19
19
import { Context } from './context' ;
20
20
import { ContextBindings , ContextTags } from './keys' ;
21
- import { transformValueOrPromise , ValueOrPromise } from './value-promise' ;
21
+ import {
22
+ transformValueOrPromise ,
23
+ tryWithFinally ,
24
+ ValueOrPromise ,
25
+ } from './value-promise' ;
22
26
const debug = debugFactory ( 'loopback:context:interceptor' ) ;
23
27
const getTargetName = DecoratorFactory . getTargetName ;
24
28
@@ -390,12 +394,13 @@ export function invokeMethodWithInterceptors(
390
394
) ;
391
395
392
396
invocationCtx . assertMethodExists ( ) ;
393
- try {
394
- const interceptors = invocationCtx . loadInterceptors ( ) ;
395
- return invokeInterceptors ( invocationCtx , interceptors ) ;
396
- } finally {
397
- invocationCtx . close ( ) ;
398
- }
397
+ return tryWithFinally (
398
+ ( ) => {
399
+ const interceptors = invocationCtx . loadInterceptors ( ) ;
400
+ return invokeInterceptors ( invocationCtx , interceptors ) ;
401
+ } ,
402
+ ( ) => invocationCtx . close ( ) ,
403
+ ) ;
399
404
}
400
405
401
406
/**
You can’t perform that action at this time.
0 commit comments