mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-17 23:16:01 +00:00
fix: apply orDefault function when already completed
This commit is contained in:
12
README.md
12
README.md
@@ -14,8 +14,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'dev.tommyjs:futur-api:2.5.0'
|
||||
compile 'dev.tommyjs:futur-lazy:2.5.0'
|
||||
compile 'dev.tommyjs:futur-api:2.5.1'
|
||||
compile 'dev.tommyjs:futur-lazy:2.5.1'
|
||||
}
|
||||
```
|
||||
### Gradle DSL
|
||||
@@ -25,8 +25,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("dev.tommyjs:futur-api:2.5.0")
|
||||
implementation("dev.tommyjs:futur-lazy:2.5.0")
|
||||
implementation("dev.tommyjs:futur-api:2.5.1")
|
||||
implementation("dev.tommyjs:futur-lazy:2.5.1")
|
||||
}
|
||||
```
|
||||
### Maven
|
||||
@@ -42,12 +42,12 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>dev.tommyjs</groupId>
|
||||
<artifactId>futur-api</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.tommyjs</groupId>
|
||||
<artifactId>futur-lazy</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
@@ -6,7 +6,7 @@ plugins {
|
||||
|
||||
subprojects {
|
||||
group = 'dev.tommyjs'
|
||||
version = '2.5.0'
|
||||
version = '2.5.1'
|
||||
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
@@ -504,11 +504,12 @@ public abstract class AbstractPromise<T> implements Promise<T> {
|
||||
|
||||
@Override
|
||||
public @NotNull Promise<T> orDefault(@NotNull ExceptionalFunction<Throwable, T> function) {
|
||||
PromiseFactory factory = getFactory();
|
||||
return useCompletion(() -> {
|
||||
CompletablePromise<T> promise = createLinked();
|
||||
addDirectListener(promise::complete, e -> runCompleter(promise, () -> promise.complete(function.apply(e))));
|
||||
return promise;
|
||||
}, getFactory()::resolve, getFactory()::error);
|
||||
}, factory::resolve, e -> supplySafe(() -> factory.resolve(function.apply(e)), factory::error));
|
||||
}
|
||||
|
||||
private static class DeferredExecutionException extends ExecutionException {
|
||||
|
||||
@@ -211,6 +211,18 @@ public final class PromiseTests {
|
||||
assert res.get() == 10;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrDefaultFunctionCompleted() {
|
||||
CompletablePromise<Integer> promise = promises.unresolved();
|
||||
promise.completeExceptionally(new IllegalStateException("Test"));
|
||||
AtomicReference<Integer> res = new AtomicReference<>();
|
||||
promise.orDefault(e -> {
|
||||
assert e instanceof IllegalStateException;
|
||||
return 10;
|
||||
}).thenPopulateReference(res);
|
||||
assert res.get() == 10;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrDefaultError() {
|
||||
CompletablePromise<Integer> promise = promises.unresolved();
|
||||
|
||||
Reference in New Issue
Block a user