@@ -212,31 +212,37 @@ describe('LoopBack Context', function() {
212
212
function runWithRequestId ( pushedValue , bindNextCb ) {
213
213
return new Promise ( function chainExecutor ( outerResolve , reject ) {
214
214
LoopBackContext . runInContext ( function concurrentChain ( ) {
215
- var middleware1 = function middleware1 ( req , res , next ) {
215
+ function middlewareBreakingCls ( req , res , next ) {
216
216
var ctx = LoopBackContext . getCurrentContext ( { bind : true } ) ;
217
217
if ( bindNextCb ) {
218
218
next = ctx . bind ( next ) ;
219
219
}
220
- ctx . set ( 'test-key' , req . pushedValue ) ;
220
+ ctx . set ( 'test-key' , pushedValue ) ;
221
221
var whenPromise = whenV377 ( ) . delay ( timeout ) ;
222
222
whenPromise . then ( next ) . catch ( reject ) ;
223
223
} ;
224
- var middleware2 = function middleware2 ( req , res , next ) {
224
+
225
+ function middlewareReadingContext ( req , res , next ) {
225
226
var ctx = LoopBackContext . getCurrentContext ( { bind : true } ) ;
226
227
var pulledValue = ctx && ctx . get ( 'test-key' ) ;
227
228
next ( null , pulledValue ) ;
228
229
} ;
229
- // Run chain
230
- var req = { pushedValue : pushedValue } ;
230
+
231
+ // Run the chain
232
+ var req = null ;
231
233
var res = null ;
232
- var next2 = function resolveWithResult ( error , result ) {
233
- outerResolve ( {
234
- pulledValue : result ,
235
- pushedValue : pushedValue ,
234
+ middlewareBreakingCls ( req , res , function ( err ) {
235
+ if ( err ) return reject ( err ) ;
236
+
237
+ middlewareReadingContext ( req , res , function ( err , result ) {
238
+ if ( err ) return reject ( err ) ;
239
+
240
+ outerResolve ( {
241
+ pulledValue : result ,
242
+ pushedValue : pushedValue ,
243
+ } ) ;
236
244
} ) ;
237
- } ;
238
- var next1 = middleware2 . bind ( null , req , res , next2 ) ;
239
- middleware1 ( req , res , next1 ) ;
245
+ } ) ;
240
246
} ) ;
241
247
} ) ;
242
248
}
0 commit comments