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

nz.sodium.CellLoop Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package nz.sodium;

/**
 * A forward reference for a {@link Cell} equivalent to the Cell that is referenced. 
 */
public final class CellLoop extends LazyCell {
    public CellLoop() {
    	super(new StreamLoop(), null);
    }

    /**
     * Resolve the loop to specify what the CellLoop was a forward reference to. It
     * must be invoked inside the same transaction as the place where the CellLoop is used.
     * This requires you to create an explicit transaction with {@link Transaction#run(Lambda0)}
     * or {@link Transaction#runVoid(Runnable)}.
     */
    public void loop(final Cell a_out)
    {
        final CellLoop me = this;
        Transaction.apply(new Lambda1() {
        	public Unit apply(final Transaction trans) {
                ((StreamLoop)me.str).loop(a_out.updates(trans));
                me.lazyInitValue = a_out.sampleLazy(trans);
                return Unit.UNIT;
            }
        });
    }

    @Override
    A sampleNoTrans()
    {
        if (!((StreamLoop)str).assigned)
            throw new RuntimeException("CellLoop sampled before it was looped");
        return super.sampleNoTrans();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy