nz.sodium.CellLoop 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;
/**
* 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