SharedSignal

A cross-thread signal struct with multiple endpoint dispatch.

Multiple slots can be connected using connect. Each of the connected slots will be called when emit is called with the arguments passed to each slot. The order of slot invocation is undefined.

Slots will always be called asynchronously in the same thread in which they were registered. Thus, SharedSignal is thread-safe, even if non-thread-safe delegates are used as slots. However, the argument types passed to emit() must be weakly shared.

Constructors

this
this()
Undocumented in source.

Members

Aliases

Slot
alias Slot = shared(void delegate(P))

Functions

connect
SignalConnection connect(Slot slot)
disconnect
void disconnect(Slot slot)
emit
void emit(P params)
Undocumented in source. Be warned that the author may not have intended to support it.
isSlotConnected
bool isSlotConnected(Slot slot)

Examples

shared(SharedSignal!int) signal;

void setup()
{
	auto mainthr = Thread.getThis();

	signal = new shared(SharedSignal!int);
	signal.connect((value){
		assert(Thread.getThis() is mainthr);
		writefln("Value: %d", value);
	}

	auto thr = new Thread({ signal.emit(42); });
	thr.run();
}

See Also

vibe.core.concurrency.isWeaklyIsolated

Meta