AsyncContext implements EvalContext { @Override public final <T> Value<T> value(Fn<T> t) { return new FuturePromise<>(this, executor, CompletableFuture.supplyAsync(t, executor)) .value(); } private  AsyncContext(Executor executor); static EvalContext create(Executor executor); @Override Value<T> evaluateInternal(Task<T> task, EvalContext context); @Override final Value<T> value(Fn<T> t); @Override final Value<T> immediateValue(T t); @Override Promise<T> promise();  }
@Test public void suppliedValueIsComputedOnExecutorThread() throws Exception { String outerThread = Thread.currentThread().getName(); AtomicReference<String> evalThread = new AtomicReference<>(); AwaitValue<String> val = new AwaitValue<>(); context.value(() -> { evalThread.set(Thread.currentThread().getName()); return "hello"; }).consume(val); assertThat(val.awaitAndGet(), is("hello")); assertThat(evalThread.get(), not(is(outerThread))); }