Table of Contents

Method Listen

Namespace
SodaFlow
Assembly
SodaFlow.dll

Listen<T>(Stream<T>, Action<T>)

Listen for events/firings on this stream, without keeping the stream 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 Stream<T> s, Action<T> handler)

Parameters

s Stream<T>

The stream.

handler Action<T>

The handler to run with each value the stream fires.

Returns

IWeakListener

An IWeakListener. A call to its Unlisten() stops the listener. Only IStrongListener is also an IDisposable.

Type Parameters

T

The type of the stream.

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 stream, or when a GC collects the listener.

This does not root the stream. Nothing here keeps the monitored graph in memory, thus the listener stops when a GC collects the stream. Keep the listener from this call where that matters, or use ListenStrong<T>(Stream<T>, Action<T>) to keep the stream in memory.