forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- turn ResultNode in an abstract class - restrict the support of CompletionStage by default; i.e. only consider CompletableFuture and CompletedStage - in some cases intentionally use "instanceof" to test interfaces as the last resort in order to mitigate the type pollution - also make Qute's version of LazyValue Loom-friendly
- Loading branch information
Showing
11 changed files
with
97 additions
and
67 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
independent-projects/qute/core/src/main/java/io/quarkus/qute/CompletionStageSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkus.qute; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import io.smallrye.mutiny.operators.AbstractUni; | ||
|
||
class CompletionStageSupport { | ||
|
||
static final String SYSTEM_PROPERTY = "quarkus.qute.unrestricted-completion-stage-support"; | ||
|
||
/** | ||
* {@code true} if any {@link CompletionStage} implementation is supported. {@code false} if only {@link CompletableFuture} | ||
* and {@link CompletedStage} are considered in the API. | ||
*/ | ||
static final boolean UNRESTRICTED = Boolean.getBoolean(SYSTEM_PROPERTY); | ||
|
||
@SuppressWarnings("unchecked") | ||
static CompletionStage<Object> toCompletionStage(Object result) { | ||
// Note that we intentionally use "instanceof" to test interfaces as the last resort in order to mitigate the "type pollution" | ||
// See https://github.com/RedHatPerf/type-pollution-agent for more information | ||
if (result instanceof CompletableFuture) { | ||
return (CompletableFuture<Object>) result; | ||
} else if (result instanceof CompletedStage) { | ||
return (CompletedStage<Object>) result; | ||
} else if (result instanceof AbstractUni) { | ||
return ((AbstractUni<Object>) result).subscribeAsCompletionStage(); | ||
} else if (UNRESTRICTED && result instanceof CompletionStage) { | ||
return (CompletionStage<Object>) result; | ||
} | ||
return CompletedStage.of(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters