1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.util.concurrent;
17
18 import java.util.concurrent.CancellationException;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeUnit;
21 import java.util.concurrent.TimeoutException;
22
23
24
25
26
27
28 public abstract class AbstractFuture<V> implements Future<V> {
29
30 @Override
31 public V get() throws InterruptedException, ExecutionException {
32 await();
33
34 Throwable cause = cause();
35 if (cause == null) {
36 return getNow();
37 }
38 if (cause instanceof CancellationException) {
39 throw (CancellationException) cause;
40 }
41 throw new ExecutionException(cause);
42 }
43
44 @Override
45 public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
46 if (await(timeout, unit)) {
47 Throwable cause = cause();
48 if (cause == null) {
49 return getNow();
50 }
51 if (cause instanceof CancellationException) {
52 throw (CancellationException) cause;
53 }
54 throw new ExecutionException(cause);
55 }
56 throw new TimeoutException();
57 }
58 }