@@ -240,7 +240,15 @@ Pipeline.prototype.execBuffer = deprecate(function () {
240
240
return execBuffer . apply ( this , arguments ) ;
241
241
} , "Pipeline#execBuffer: Use Pipeline#exec instead" ) ;
242
242
243
- Pipeline . prototype . exec = function ( callback : CallbackFunction ) {
243
+ // NOTE: To avoid an unhandled promise rejection, this will unconditionally always return this.promise,
244
+ // which always has the rejection handled by standard-as-callback
245
+ // adding the provided rejection callback.
246
+ //
247
+ // If a different promise instance were returned, that promise would cause its own unhandled promise rejection
248
+ // errors, even if that promise unconditionally resolved to **the resolved value of** this.promise.
249
+ Pipeline . prototype . exec = function (
250
+ callback : CallbackFunction
251
+ ) : Promise < Array < any > > {
244
252
// Wait for the cluster to be connected, since we need nodes information before continuing
245
253
if ( this . isCluster && ! this . redis . slots . length ) {
246
254
if ( this . redis . status === "wait" ) this . redis . connect ( ) . catch ( noop ) ;
@@ -338,17 +346,19 @@ Pipeline.prototype.exec = function (callback: CallbackFunction) {
338
346
339
347
// In cluster mode, always load scripts before running the pipeline
340
348
if ( this . isCluster ) {
341
- return pMap ( scripts , ( script ) => _this . redis . script ( "load" , script . lua ) , {
349
+ pMap ( scripts , ( script ) => _this . redis . script ( "load" , script . lua ) , {
342
350
concurrency : 10 ,
343
- } ) . then ( function ( ) {
344
- for ( let i = 0 ; i < scripts . length ; i ++ ) {
345
- _this . redis . _addedScriptHashes [ scripts [ i ] . sha ] = true ;
346
- }
347
- return execPipeline ( ) ;
348
- } ) ;
351
+ } )
352
+ . then ( function ( ) {
353
+ for ( let i = 0 ; i < scripts . length ; i ++ ) {
354
+ _this . redis . _addedScriptHashes [ scripts [ i ] . sha ] = true ;
355
+ }
356
+ } )
357
+ . then ( execPipeline , this . reject ) ;
358
+ return this . promise ;
349
359
}
350
360
351
- return this . redis
361
+ this . redis
352
362
. script (
353
363
"exists" ,
354
364
scripts . map ( ( { sha } ) => sha )
@@ -371,8 +381,9 @@ Pipeline.prototype.exec = function (callback: CallbackFunction) {
371
381
for ( let i = 0 ; i < scripts . length ; i ++ ) {
372
382
_this . redis . _addedScriptHashes [ scripts [ i ] . sha ] = true ;
373
383
}
374
- return execPipeline ( ) ;
375
- } ) ;
384
+ } )
385
+ . then ( execPipeline , this . reject ) ;
386
+ return this . promise ;
376
387
377
388
function execPipeline ( ) {
378
389
let data = "" ;
0 commit comments