Signal.connectBefore

Add a handler to be called before another handler.

struct Signal(Types...)
@trusted
T
connectBefore
(
T
U
)
if (
isHandler!(T, Types) &&
isHandler!(U, Types)
)

Parameters

beforeThis T

The new attached handler will be called after this handler

handler U

The handler to be attached

Return Value

Type: T

The handler that has been connected

Exception if beforeThis is not registered (Always, even if asserts are disabled)

Throws

Exception if handler is already registered (Only if asserts are enabled! Does not throw in release mode!)

Examples

bool firstCalled, secondCalled, thirdCalled;
@safe void handler1() {firstCalled = true;}
@safe void handler2()
{
    secondCalled = true;
    assert(firstCalled);
    assert(!thirdCalled);
}
@safe void handler3()
{
    thirdCalled = true;
    assert(firstCalled);
    assert(secondCalled);
}
Signal!() onTest;
onTest ~= &handler1;
onTest ~= &handler3;
onTest.connectBefore(&handler3, &handler2);
onTest();
assert(firstCalled && secondCalled && thirdCalled);

Meta