nz.sodium.CoalesceHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sodium Show documentation
Show all versions of sodium Show documentation
A Functional Reactive Programming (FRP) system for Java
package nz.sodium;
class CoalesceHandler implements TransactionHandler
{
public CoalesceHandler(Lambda2 f, StreamWithSend out)
{
this.f = f;
this.out = out;
}
private Lambda2 f;
private StreamWithSend out;
private boolean accumValid = false;
private A accum;
@Override
public void run(Transaction trans1, A a) {
if (accumValid)
accum = f.apply(accum, a);
else {
final CoalesceHandler thiz = this;
trans1.prioritized(out.node, new Handler() {
public void run(Transaction trans2) {
out.send(trans2, thiz.accum);
thiz.accumValid = false;
thiz.accum = null;
}
});
accum = a;
accumValid = true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy