nz.sodium.StreamLoop 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 Stream} equivalent to the Stream that is referenced.
*/
public class StreamLoop extends StreamWithSend {
boolean assigned = false;
public StreamLoop()
{
if (Transaction.getCurrentTransaction() == null)
throw new RuntimeException("StreamLoop/CellLoop must be used within an explicit transaction");
}
/**
* Resolve the loop to specify what the StreamLoop was a forward reference to. It
* must be invoked inside the same transaction as the place where the StreamLoop is used.
* This requires you to create an explicit transaction with {@link Transaction#run(Lambda0)}
* or {@link Transaction#runVoid(Runnable)}.
*/
public void loop(final Stream ea_out)
{
if (assigned)
throw new RuntimeException("StreamLoop looped more than once");
assigned = true;
final StreamLoop me = this;
Transaction.runVoid(new Runnable() {
public void run() {
unsafeAddCleanup(ea_out.listen_(StreamLoop.this.node, new TransactionHandler() {
public void run(Transaction trans, A a) {
me.send(trans, a);
}
}));
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy