All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nz.sodium.CoalesceHandler Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
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