Method Listen
- Namespace
- SodaFlow
- Assembly
- SodaFlow.dll
Listen<T>(Cell<T>, Action<T>)
Listen for updates to the value of this cell, without keeping the cell alive. The returned IWeakListener. A call to Unlisten() stops the listener, and the listener also stops when a GC collects it. This is an OPERATIONAL mechanism for interfacing between the world of I/O and FRP.
public static IWeakListener Listen<T>(this Cell<T> c, Action<T> handler)
Parameters
Returns
- IWeakListener
An IWeakListener. A call to its Unlisten() stops the listener. Only IStrongListener is also an IDisposable.
Type Parameters
TThe type of the cell.
Remarks
Make no assumption about the thread that calls the handler, and the handler must not block. The handler must not call Send<T>(StreamSink<T>, T) or Send<T>(CellSink<T>, T). They throw an exception, because this method is not for the definition of a new primitive.
With no call to Unlisten(), the listener continues. It stops when a GC collects the cell, or when a GC collects the listener.
This does not root the cell. Nothing here keeps the monitored graph in memory, thus the listener stops when a GC collects the cell. Keep the listener from this call where that matters, or use ListenStrong<T>(Cell<T>, Action<T>) to keep the cell in memory.