use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.
the class GeneratorTest method test.
@Test
public void test() {
Generator generator = Actors.AsActor(Generator.class);
try {
generator.run().await(1000 * 1000l);
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
}
try {
generator.run().await(1 * 1000l);
Assert.assertTrue(false);
} catch (Exception e) {
e.printStackTrace();
}
// test outside actor thread
BiConsumer<Long, Boolean> outside = (timout, expectTO) -> {
// +1 == fin signal
PromiseLatch finished = new PromiseLatch(5 * 5 + 1);
generator.generate(100, (intarr, err) -> {
if (!Actor.isErrorOrComplete(err)) {
System.out.println("-> [" + intarr[0] + "," + intarr[1] + "]");
}
finished.countDown();
});
try {
finished.getPromise().await(timout);
if (expectTO)
Assert.assertTrue(false);
} catch (Exception e) {
e.printStackTrace();
if (!expectTO)
Assert.assertTrue(false);
}
};
outside.accept(1000l, true);
outside.accept(100 * 1000l, false);
}
use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.
the class Actors method awaitSettle.
// changed to non recursive due to stackoverflows ..
private static <T> void awaitSettle(final List<IPromise<T>> futures, final IPromise result) {
PromiseLatch latch = new PromiseLatch(futures.size());
latch.getPromise().then(() -> result.complete(futures, null));
futures.forEach(fut -> fut.then(() -> latch.countDown()));
}
use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.
the class Actors method awaitSettle.
// end static API
//
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// helper
// changed to non recursive due to stackoverflows ..
private static <T> void awaitSettle(final IPromise<T>[] futures, final IPromise result) {
PromiseLatch latch = new PromiseLatch(futures.length);
latch.getPromise().then(() -> result.complete(futures, null));
for (int i = 0; i < futures.length; i++) {
futures[i].then(() -> latch.countDown());
}
}
Aggregations