observable 1.1.0

Provides event handling facilities based on observable and signal slot approaches


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Observable and signal/slot implementation

This library provides event handling mechanisms on two abstraction levels. Signals/slots are a direct way for events to be propagated to any number of event receivers. The propagation happens synchronously and has very low overhead, computationally and memory consumption wise.

Observables on the other hand allow each observer to process events asynchronously using a separate event queue. The advantage of this approach is that each observer can process events in order, but independent of the timing of the source. Additionally, observables can be composed, manipulated and augmented using a range-like API.

Both, signals and observables, support storing extra data to avoid the need for creating heap closures when listening for events.

Build status

Signal/slot example

class Slider {
    private {
        double m_value = 0.0;
        Signal!double m_valueChangeSignal;
    }

    @property ref SignalSocket!double valueChangeSignal()
    {
        return m_valueChangeSignal.socket;
    }

    @property void value(double new_value)
    {
        m_value = new_value;
        m_valueChangeSignal.emit(new_value);
    }
}

class Label {
    @property void caption(string caption);
}

class MyDialog {
    private {
        Label m_label;
        Slider m_slider;
        SignalConnection m_valueConnection;
    }

    this()
    {
        m_label = new Label;

        m_slider = new Slider;
        m_slider.valueChangeSignal.connect(m_valueConnection,
            (value) => slider.caption = value.to!string);
    }
}

Observable example

class Slider {
    private {
        double m_value = 0.0;
        ObservableSource!double m_valueChanges;
    }

    @property ref Observable!double valueChanges()
    {
        return m_valueChanges.observable;
    }

    @property void value(double new_value)
    {
        m_value = new_value;
        m_valueChanges.put(new_value);
    }
}

class Label {
    @property void caption(string caption);
}

class MyDialog {
    private {
        Label m_label;
        Slider m_slider;
        SignalConnection m_valueConnection;
    }

    this()
    {
        m_label = new Label;

        m_slider = new Slider;

        runTask({
            foreach (value; m_slider.valueChanges.subscribe)
                m_label.caption = value.to!string;
        });
    }
}
Authors:
  • Sönke Ludwig
Dependencies:
vibe-core
Versions:
1.1.0 2021-Aug-20
1.0.3 2021-Jul-02
1.0.2 2021-Jul-02
1.0.1 2021-Jul-02
1.0.0 2021-May-25
Show all 6 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 7 downloads this month

  • 67 downloads total

Score:
0.7
Short URL:
observable.dub.pm