Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 23, 2024
1 parent b71e4a2 commit 68ab187
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
- `anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF``anyOf`
- 更安全的使用方式,如
- 支持设置缺省的业务线程池(`CffuFactoryBuilder#newCffuFactoryBuilder(executor)`方法)
- `cffuJoin(timeout, unit)`方法:支持超时的`join`的方法
- `join(timeout, unit)`方法:支持超时的`join`的方法
- 支持禁止强制篡改(`CffuFactoryBuilder#forbidObtrudeMethods`方法)
- 在类方法附加完善的代码质量注解(如`@NonNull``@Nullable``@CheckReturnValue``@Contract`等),在编码时`IDE`能尽早提示出问题
- 💪 **已有功能的增强**,如
Expand Down Expand Up @@ -498,7 +498,7 @@ public class ConcurrencyStrategyDemo {
- 主业务逻辑阻塞,没有机会做相应的处理,以及时响应用户
- 会费掉一个线程,线程是很有限的资源(一般几百个),耗尽线程意味着服务瘫痪故障

`cffuJoin(timeout, unit)`方法即支持超时的`join`的方法;就像`cf.get(timeout, unit)` 之于 `cf.get()`
`join(timeout, unit)`方法即支持超时的`join`的方法;就像`cf.get(timeout, unit)` 之于 `cf.get()`

这个新方法使用简单类似,不附代码示例。

Expand Down
10 changes: 5 additions & 5 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ public <U> Cffu<U> handleAsync(
* @throws ExecutionException if the computation threw an exception
* @throws InterruptedException if the current thread was interrupted while waiting
* @see #join()
* @see #cffuJoin(long, TimeUnit)
* @see #join(long, TimeUnit)
* @see #getNow(Object)
* @see #resultNow()
* @see #get(long, TimeUnit)
Expand All @@ -1286,7 +1286,7 @@ public T get() throws InterruptedException, ExecutionException {
* @throws ExecutionException if the computation threw an exception
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws TimeoutException if the wait timed out
* @see #cffuJoin(long, TimeUnit)
* @see #join(long, TimeUnit)
* @see #getNow(Object)
* @see #resultNow()
* @see #join()
Expand All @@ -1312,7 +1312,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution
* @throws CancellationException if the computation was cancelled
* @throws CompletionException if this future completed exceptionally
* or a completion computation threw an exception
* @see #cffuJoin(long, TimeUnit)
* @see #join(long, TimeUnit)
* @see #getNow(Object)
* @see #resultNow()
* @see #get(long, TimeUnit)
Expand Down Expand Up @@ -1363,7 +1363,7 @@ public T join() {
*/
@Blocking
@Nullable
public T cffuJoin(long timeout, TimeUnit unit) {
public T join(long timeout, TimeUnit unit) {
checkMinimalStage();

return CompletableFutureUtils.join(cf, timeout, unit);
Expand All @@ -1379,7 +1379,7 @@ public T cffuJoin(long timeout, TimeUnit unit) {
* @throws CompletionException if this future completed exceptionally
* or a completion computation threw an exception
* @see #resultNow()
* @see #cffuJoin(long, TimeUnit)
* @see #join(long, TimeUnit)
* @see #join()
* @see #get(long, TimeUnit)
* @see #get()
Expand Down
8 changes: 4 additions & 4 deletions cffu-core/src/test/java/io/foldright/cffu/CffuTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class CffuTest {
@Test
void test_cffuJoin() {
// Completed Future
assertEquals(n, cffuFactory.completedFuture(n).cffuJoin(1, TimeUnit.MILLISECONDS));
assertEquals(n, cffuFactory.completedFuture(n).join(1, TimeUnit.MILLISECONDS));

// Incomplete Future -> CompletionException with TimeoutException
Cffu<Object> incomplete = cffuFactory.newIncompleteCffu();
try {
incomplete.cffuJoin(1, TimeUnit.MILLISECONDS);
incomplete.join(1, TimeUnit.MILLISECONDS);
fail();
} catch (CompletionException expected) {
assertEquals(TimeoutException.class, expected.getCause().getClass());
Expand All @@ -65,7 +65,7 @@ void test_cffuJoin() {
// Failed Future -> CompletionException
Cffu<Object> failed = cffuFactory.failedFuture(rte);
try {
failed.cffuJoin(1, TimeUnit.MILLISECONDS);
failed.join(1, TimeUnit.MILLISECONDS);
fail();
} catch (CompletionException expected) {
assertSame(rte, expected.getCause());
Expand All @@ -77,7 +77,7 @@ void test_cffuJoin() {
sleep(300);
return 42;
});
assertEquals(42, cffu.cffuJoin(3, TimeUnit.SECONDS));
assertEquals(42, cffu.join(3, TimeUnit.SECONDS));
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private fun <T> Cffu<T>.shouldMinCffu(recursive: Boolean = false) {
////////////////////////////////////////////////////////////

shouldThrow<UnsupportedOperationException> {
cffuJoin(1, TimeUnit.MILLISECONDS)
join(1, TimeUnit.MILLISECONDS)
}.message shouldBe "unsupported because this is a minimal stage"
shouldThrow<UnsupportedOperationException> {
cffuState()
Expand Down Expand Up @@ -504,7 +504,7 @@ private fun <T> Cffu<T>.shouldNotMinCffu(recursive: Boolean = false) {
// Cffu specified methods
////////////////////////////////////////////////////////////

cffuJoin(1, TimeUnit.MILLISECONDS)
join(1, TimeUnit.MILLISECONDS)
cffuState()

//# Cffu Re-Config methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ fun <T> CompletableFuture<T>.cffuExceptionallyComposeAsync(
* @see CompletableFuture.join
*/
@Suppress("UNCHECKED_CAST")
fun <T> CompletableFuture<T>.cffuJoin(timeout: Long, unit: TimeUnit): T =
fun <T> CompletableFuture<T>.join(timeout: Long, unit: TimeUnit): T =
CompletableFutureUtils.join(this, timeout, unit) as T

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class CompletableFutureExtensionsTest : FunSpec({
val cf = CompletableFuture.completedFuture(n)
val ff = CompletableFutureUtils.failedFuture<Int>(rte)

cf.cffuJoin(1, TimeUnit.MILLISECONDS) shouldBe n
cf.join(1, TimeUnit.MILLISECONDS) shouldBe n
cf.cffuResultNow() shouldBe n
ff.cffuExceptionNow() shouldBeSameInstanceAs rte

Expand Down

0 comments on commit 68ab187

Please sign in to comment.