ruk·si

UniRx
CreateShoutObserver

Updated at 2017-07-28 20:55

Observer.Create Create a new observer that defines how to act on stream events. I use the following CreateShoutObserver all around my notes for simplicity.

Func<UniRx.IObserver<int>> CreateShoutObserver = () =>
{
    return Observer.Create<int>(
        (number) => Debug.Log("OnNext: " + number),
        (error) => Debug.Log("OnError: " + error),  // optional
        () => Debug.Log("OnCompleted")              // optional
    );
};

// Or as more generic variant:
private static UniRx.IObserver<T> CreateShoutObserver<T>()
{
    return Observer.Create<T>(
        (val) => Debug.Log("OnNext: " + val),
        (err) => Debug.Log("OnError: " + err),  // optional
        () => Debug.Log("OnCompleted")          // optional
    );
}