Last active
December 15, 2015 23:38
-
-
Save artembilan/79394d258d5550b45b5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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