diff src/fschmidt/util/java/FutureValue.java @ 68:00520880ad02

add fschmidt source
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 05 Oct 2025 17:24:15 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fschmidt/util/java/FutureValue.java	Sun Oct 05 17:24:15 2025 -0600
@@ -0,0 +1,27 @@
+package fschmidt.util.java;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+
+
+public abstract class FutureValue<V> {
+
+	private final FastFuture<V> ft = new FastFuture<V>(new Callable<V>() {
+		public V call() throws Exception {
+			return compute();
+		}
+	});
+
+	public V get() throws ComputationException {
+		ft.run();
+		try {
+			return ft.get();
+		} catch(InterruptedException e) {
+			throw new ComputationException(e);
+		} catch(ExecutionException e) {
+			throw ComputationException.newInstance(e);
+		}
+	}
+
+	protected abstract V compute() throws Exception;
+}