Skip to content

Commit 05e9cd3

Browse files
bachdendungba88
authored andcommitted
added timeoutAfter to Promise interface (#2)
* added `timeoutAfter` to Promise interface * reset .project * remove eclipse project files
1 parent 008fe1a commit 05e9cd3

14 files changed

+235
-90
lines changed

.classpath

Lines changed: 0 additions & 27 deletions
This file was deleted.

.gitignore

Lines changed: 174 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,174 @@
1-
# Compiled class file
2-
*.class
3-
4-
# Log file
5-
*.log
6-
7-
# BlueJ files
8-
*.ctxt
9-
10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
12-
13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.ear
17-
*.zip
18-
*.tar.gz
19-
*.rar
20-
21-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22-
hs_err_pid*
23-
/bin/
24-
/target/
25-
.classpath
26-
.settings
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
25+
logs
26+
target
27+
bin
28+
.settings
29+
.classpath
30+
.project
31+
32+
33+
HELP.md
34+
/target/
35+
!.mvn/wrapper/maven-wrapper.jar
36+
37+
### STS ###
38+
.apt_generated
39+
.classpath
40+
.factorypath
41+
.project
42+
.settings
43+
.springBeans
44+
.sts4-cache
45+
46+
### IntelliJ IDEA ###
47+
.idea
48+
*.iws
49+
*.iml
50+
*.ipr
51+
52+
### NetBeans ###
53+
/nbproject/private/
54+
/nbbuild/
55+
/dist/
56+
/nbdist/
57+
/.nb-gradle/
58+
/build/
59+
60+
### VS Code ###
61+
.vscode/
62+
63+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
64+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
65+
66+
# User-specific stuff
67+
.idea/**/workspace.xml
68+
.idea/**/tasks.xml
69+
.idea/**/usage.statistics.xml
70+
.idea/**/dictionaries
71+
.idea/**/shelf
72+
73+
# Generated files
74+
.idea/**/contentModel.xml
75+
76+
# Sensitive or high-churn files
77+
.idea/**/dataSources/
78+
.idea/**/dataSources.ids
79+
.idea/**/dataSources.local.xml
80+
.idea/**/sqlDataSources.xml
81+
.idea/**/dynamic.xml
82+
.idea/**/uiDesigner.xml
83+
.idea/**/dbnavigator.xml
84+
85+
# Gradle
86+
.idea/**/gradle.xml
87+
.idea/**/libraries
88+
89+
# Gradle and Maven with auto-import
90+
# When using Gradle or Maven with auto-import, you should exclude module files,
91+
# since they will be recreated, and may cause churn. Uncomment if using
92+
# auto-import.
93+
# .idea/modules.xml
94+
# .idea/*.iml
95+
# .idea/modules
96+
97+
# CMake
98+
cmake-build-*/
99+
100+
# Mongo Explorer plugin
101+
.idea/**/mongoSettings.xml
102+
103+
# File-based project format
104+
*.iws
105+
106+
# IntelliJ
107+
out/
108+
109+
# mpeltonen/sbt-idea plugin
110+
.idea_modules/
111+
112+
# JIRA plugin
113+
atlassian-ide-plugin.xml
114+
115+
# Cursive Clojure plugin
116+
.idea/replstate.xml
117+
118+
# Crashlytics plugin (for Android Studio and IntelliJ)
119+
com_crashlytics_export_strings.xml
120+
crashlytics.properties
121+
crashlytics-build.properties
122+
fabric.properties
123+
124+
# Editor-based Rest Client
125+
.idea/httpRequests
126+
127+
# Android studio 3.1+ serialized cache file
128+
.idea/caches/build_file_checksums.ser
129+
*#
130+
*.iml
131+
*.ipr
132+
*.iws
133+
*.jar
134+
*.sw?
135+
*~
136+
.#*
137+
.*.md.html
138+
.DS_Store
139+
.classpath
140+
.factorypath
141+
.gradle
142+
.idea
143+
.metadata
144+
.project
145+
.recommenders
146+
.settings
147+
.springBeans
148+
/build
149+
/code
150+
MANIFEST.MF
151+
_site/
152+
activemq-data
153+
bin
154+
build
155+
build.log
156+
dependency-reduced-pom.xml
157+
dump.rdb
158+
interpolated*.xml
159+
lib/
160+
manifest.yml
161+
overridedb.*
162+
settings.xml
163+
target
164+
transaction-logs
165+
.flattened-pom.xml
166+
secrets.yml
167+
.gradletasknamecache
168+
.sts4-cache
169+
170+
.idea
171+
*.iml
172+
173+
*.iml
174+
dist

.project

Lines changed: 0 additions & 23 deletions
This file was deleted.

.settings/org.eclipse.core.resources.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 5 deletions
This file was deleted.

.settings/org.eclipse.m2e.core.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/org/joo/promise4j/Promise.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ public default <D_OUT, F_OUT extends Throwable> Promise<D_OUT, F_OUT> then(
152152
PipeDoneCallback<D, D_OUT, F_OUT> callback) {
153153
return pipeDone(callback);
154154
}
155-
155+
156156
public Promise<D, F> when(Predicate<D> predicate, PipeDoneCallback<D, D, F> callback);
157157

158158
public <D_OUT, F_OUT extends Throwable> Promise<D_OUT, F_OUT> then(PipeAlwaysCallback<D, D_OUT, F, F_OUT> callback);
159159

160+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier);
161+
160162
public static <D_OUT, F_OUT extends Throwable> Promise<D_OUT, F_OUT> ofCause(F_OUT cause) {
161163
return new SimpleFailurePromise<>(cause);
162164
}
@@ -190,4 +192,5 @@ public static <D, F extends Throwable> Promise<D, F> supply(Executor executor, S
190192
});
191193
return deferred;
192194
}
195+
193196
}

src/main/java/org/joo/promise4j/impl/AsyncDeferredObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public Deferred<D, F> withTimeout(long timeout, TimeUnit unit, Supplier<F> excep
150150
return this;
151151
}
152152

153+
@Override
154+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
155+
withTimeout(duration, unit, exceptionSupplier);
156+
return this;
157+
}
158+
153159
@Override
154160
public DeferredStatus getStatus() {
155161
return status;

src/main/java/org/joo/promise4j/impl/CompletableDeferredObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public Deferred<D, F> withTimeout(long timeout, TimeUnit unit, Supplier<F> excep
102102
return this;
103103
}
104104

105+
@Override
106+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
107+
withTimeout(duration, unit, exceptionSupplier);
108+
return this;
109+
}
110+
105111
@Override
106112
public DeferredStatus getStatus() {
107113
if (!future.isDone())

src/main/java/org/joo/promise4j/impl/SimpleDeferredObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public Deferred<D, F> withTimeout(long timeout, TimeUnit unit, Supplier<F> excep
150150
return this;
151151
}
152152

153+
@Override
154+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
155+
withTimeout(duration, unit, exceptionSupplier);
156+
return this;
157+
}
158+
153159
@Override
154160
public DeferredStatus getStatus() {
155161
return status;

src/main/java/org/joo/promise4j/impl/SimpleDonePromise.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.concurrent.TimeUnit;
44
import java.util.concurrent.TimeoutException;
5+
import java.util.function.Supplier;
56

67
import org.joo.promise4j.AlwaysCallback;
78
import org.joo.promise4j.DeferredStatus;
@@ -49,4 +50,10 @@ public D get(long timeout, TimeUnit unit) throws PromiseException, TimeoutExcept
4950
public DeferredStatus getStatus() {
5051
return DeferredStatus.RESOLVED;
5152
}
53+
54+
@Override
55+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
56+
// do nothing
57+
return this;
58+
}
5259
}

src/main/java/org/joo/promise4j/impl/SimpleFailurePromise.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.concurrent.TimeUnit;
44
import java.util.concurrent.TimeoutException;
5+
import java.util.function.Supplier;
56

67
import org.joo.promise4j.AlwaysCallback;
78
import org.joo.promise4j.DeferredStatus;
@@ -49,4 +50,10 @@ public D get(long timeout, TimeUnit unit) throws PromiseException, TimeoutExcept
4950
public DeferredStatus getStatus() {
5051
return DeferredStatus.REJECTED;
5152
}
53+
54+
@Override
55+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
56+
// do nothing
57+
return this;
58+
}
5259
}

src/main/java/org/joo/promise4j/impl/SyncDeferredObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,10 @@ public Deferred<D, F> withTimeout(long timeout, TimeUnit unit, Supplier<F> excep
159159
public DeferredStatus getStatus() {
160160
return status;
161161
}
162+
163+
@Override
164+
public Promise<D, F> timeoutAfter(long duration, TimeUnit unit, Supplier<F> exceptionSupplier) {
165+
withTimeout(duration, unit, exceptionSupplier);
166+
return this;
167+
}
162168
}

0 commit comments

Comments
 (0)