SyncContext implements EvalContext { @Override public <T> Value<T> value(Fn<T> value) { final Promise<T> promise = promise(); try { promise.set(value.get()); } catch (Throwable t) { promise.fail(t); } return promise.value(); } private  SyncContext(); static EvalContext create(); @Override Value<T> value(Fn<T> value); @Override Promise<T> promise();  }
@Test public void suppliedValueIsComputedOnSameThread() 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(), is(outerThread)); }