RetResult增加CompletableFuture相关方法
This commit is contained in:
@@ -7,7 +7,7 @@ package org.redkale.service;
|
|||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
@@ -93,6 +93,10 @@ public class RetResult<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<RetResult<T>> toFuture() {
|
||||||
|
return CompletableFuture.completedFuture(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static RetResult success() {
|
public static RetResult success() {
|
||||||
return new RetResult();
|
return new RetResult();
|
||||||
}
|
}
|
||||||
@@ -109,6 +113,14 @@ public class RetResult<T> {
|
|||||||
return CompletableFuture.completedFuture(new RetResult(result));
|
return CompletableFuture.completedFuture(new RetResult(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> RetResult<T> get(CompletableFuture<RetResult<T>> future, long timeout, TimeUnit unit) {
|
||||||
|
try {
|
||||||
|
return future.get(timeout, unit);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static RetResult<Map<String, String>> map(String... items) {
|
public static RetResult<Map<String, String>> map(String... items) {
|
||||||
return new RetResult(Utility.ofMap(items));
|
return new RetResult(Utility.ofMap(items));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user