Skip to content

Instantly share code, notes, and snippets.

@RuedigerMoeller
Last active August 29, 2015 14:06
Show Gist options
  • Save RuedigerMoeller/10c583819616f2563969 to your computer and use it in GitHub Desktop.
Save RuedigerMoeller/10c583819616f2563969 to your computer and use it in GitHub Desktop.
emulation of scala's async macro
private static void testRun(RLTable<TCRecord> table, TCMutator mutator, ClientActor client) {
async(
() -> mutator.$init(table),
() -> {
client.$run(table);
return mutator.$run(table, 1000, null);
},
() -> table.$sync(),
() -> client.$unsubscribe(table),
() -> client.$checkCorrectness(table)
).then( (res, err) -> {
if (err == null) {
System.out.println("NEXT RUN");
table.$sync();
testRun(table, mutator, client);
} else {
System.out.println(err);
System.exit(1);
}
});
}
// Same code with pure future chaining
private static void testRun(RLTable<TCRecord> table, TCMutator mutator, ClientActor client) {
mutator.$init(table).then(() -> {
client.$run(table);
mutator.$run(table, 1000, null).then( () ->
table.$sync().then( () ->
client.$unsubscribe(table).then( () ->
client.$checkCorrectness(table).then((res, err) -> {
if (err == null) {
System.out.println("NEXT RUN");
table.$sync();
testRun(table, mutator, client);
} else {
System.out.println(err);
System.exit(1);
}
})
)
)
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment