package aQute.lib.promise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.stream.Collector;

import org.osgi.util.promise.Promise;
import org.osgi.util.promise.PromiseFactory;

public class PromiseExecutor extends PromiseFactory implements Executor {

	public PromiseExecutor() {
		this((runnable) -> runnable.run());
	}

	public PromiseExecutor(Executor executor) {
		super(Objects.requireNonNull(executor), null);
	}

	@Override
	public <V> Promise<V> submit(Callable< ? extends V> task) {
		return super.submit(task);
	}

	@Override
	public void execute(Runnable runnable) {
		executor().execute(runnable);
	}

	@Override
	public Executor executor() {
		return super.executor();
	}

	public <V> Collector<Promise<V>,List<Promise<V>>,Promise<List<V>>> toPromise() {
		return Collector.of(ArrayList::new, List::add, PromiseExecutor::combiner, this::all);
	}

	private static <E, C extends Collection<E>> C combiner(C t, C u) {
		t.addAll(u);
		return t;
	}
}

@@ -21,16 +21,65 @@
 omise;%0A%0A
+import static java.util.Objects.requireNonNull;%0A%0A
 import j
@@ -94,24 +94,24 @@
 .ArrayList;%0A
-
 import java.
@@ -154,34 +154,8 @@
 st;%0A
-import java.util.Objects;%0A
 impo
@@ -226,16 +226,70 @@
 ecutor;%0A
+import java.util.concurrent.ScheduledExecutorService;%0A
 import j
@@ -474,17 +474,16 @@
 cutor %7B%0A
-%0A
 %09public 
@@ -508,39 +508,28 @@
 %7B%0A%09%09
-this((runnable) -%3E runnable.run
+super(inlineExecutor
 ());
@@ -586,24 +586,136 @@
 %09%09super(
-Objects.
+requireNonNull(executor));%0A%09%7D%0A%0A%09public PromiseExecutor(Executor executor, ScheduledExecutorService scheduled) %7B%0A%09%09super(
 requireN
@@ -736,12 +736,33 @@
 r), 
-null
+requireNonNull(scheduled)
 );%0A%09
@@ -995,24 +995,24 @@
 xecutor() %7B%0A
-
 %09%09return sup
@@ -1026,24 +1026,130 @@
 utor();%0A%09%7D%0A%0A
+%09@Override%0A%09public ScheduledExecutorService scheduledExecutor() %7B%0A%09%09return super.scheduledExecutor();%0A%09%7D%0A%0A
 %09public %3CV%3E 

Allow specifying scheduled executor for PromiseExecutor