Skip to content

Instantly share code, notes, and snippets.

@artembilan
Last active December 15, 2015 23:38
Show Gist options
  • Save artembilan/79394d258d5550b45b5a to your computer and use it in GitHub Desktop.
Save artembilan/79394d258d5550b45b5a to your computer and use it in GitHub Desktop.
@Test
public void testParallelPromises() throws InterruptedException {
Environment environment = new Environment();
final AtomicBoolean first = new AtomicBoolean(true);
for (int i = 0; i < 10; i++) {
final Promise<String> promise = Promises.task(environment, () -> {
if (!first.getAndSet(false)) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
return "foo";
}
);
String result = promise.await(10, TimeUnit.SECONDS);
System.out.println(result);
assertNotNull(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment