@@ -596,12 +596,7 @@ public static <I> Mono<I> fromDirect(Publisher<? extends I> source){
596
596
Mono <I > extracted = (Mono <I >) wrapper .source ;
597
597
boolean shouldWrapExtracted =
598
598
ContextPropagationSupport .shouldWrapPublisher (extracted );
599
- if (!shouldWrapExtracted ) {
600
- return extracted ;
601
- } else {
602
- // Skip assembly hook
603
- return wrap (extracted , false );
604
- }
599
+ return shouldWrapExtracted ? wrap (extracted , false ) : extracted ;
605
600
}
606
601
607
602
//we delegate to `wrap` and apply assembly hooks
@@ -5413,39 +5408,30 @@ static <T> Mono<T> wrap(Publisher<T> source, boolean enforceMonoContract) {
5413
5408
//some sources can be considered already assembled monos
5414
5409
//all conversion methods (from, fromDirect, wrap) must accommodate for this
5415
5410
boolean shouldWrap = ContextPropagationSupport .shouldWrapPublisher (source );
5411
+
5416
5412
if (source instanceof Mono ) {
5417
- if (!shouldWrap ) {
5418
- return (Mono <T >) source ;
5419
- }
5420
- return ContextPropagation .monoRestoreThreadLocals ((Mono <? extends T >) source );
5413
+ return shouldWrap
5414
+ ? ContextPropagation .monoRestoreThreadLocals ((Mono <? extends T >) source )
5415
+ : (Mono <T >) source ;
5421
5416
}
5422
5417
5423
5418
if (source instanceof FluxSourceMono || source instanceof FluxSourceMonoFuseable ) {
5424
- @ SuppressWarnings ("unchecked" ) Mono <T > extracted =
5425
- (Mono <T >) ((FluxFromMonoOperator <T , T >) source ).source ;
5426
- boolean shouldWrapExtracted =
5427
- ContextPropagationSupport .shouldWrapPublisher (extracted );
5428
- if (!shouldWrapExtracted ) {
5429
- return extracted ;
5430
- }
5431
- return ContextPropagation .monoRestoreThreadLocals (extracted );
5419
+ @ SuppressWarnings ("unchecked" ) Mono <T > extracted = (Mono <T >) ((FluxFromMonoOperator <T , T >) source ).source ;
5420
+ return ContextPropagationSupport .shouldWrapPublisher (extracted )
5421
+ ? ContextPropagation .monoRestoreThreadLocals (extracted )
5422
+ : extracted ;
5432
5423
}
5433
5424
5434
5425
if (source instanceof Flux && source instanceof Callable ) {
5435
- @ SuppressWarnings ("unchecked" ) Callable <T > m = (Callable <T >) source ;
5436
- return Flux .wrapToMono (m );
5426
+ @ SuppressWarnings ("unchecked" )
5427
+ Callable <T > callable = (Callable <T >) source ;
5428
+ return Flux .wrapToMono (callable );
5437
5429
}
5438
5430
5439
5431
Mono <T > target ;
5440
-
5441
5432
//equivalent to what from used to be, without assembly hooks
5442
5433
if (enforceMonoContract ) {
5443
- if (source instanceof Flux ) {
5444
- target = new MonoNext <>((Flux <T >) source );
5445
- } else {
5446
- target = new MonoFromPublisher <>(source );
5447
- }
5448
- //equivalent to what fromDirect used to be without onAssembly
5434
+ target = source instanceof Flux ? new MonoNext <>((Flux <T >) source ) : new MonoFromPublisher <>(source );
5449
5435
} else if (source instanceof Flux && source instanceof Fuseable ) {
5450
5436
target = new MonoSourceFluxFuseable <>((Flux <T >) source );
5451
5437
} else if (source instanceof Flux ) {
@@ -5456,10 +5442,7 @@ static <T> Mono<T> wrap(Publisher<T> source, boolean enforceMonoContract) {
5456
5442
target = new MonoSource <>(source );
5457
5443
}
5458
5444
5459
- if (shouldWrap ) {
5460
- return ContextPropagation .monoRestoreThreadLocals (target );
5461
- }
5462
- return target ;
5445
+ return shouldWrap ? ContextPropagation .monoRestoreThreadLocals (target ) : target ;
5463
5446
}
5464
5447
5465
5448
@ SuppressWarnings ("unchecked" )
0 commit comments