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(); }
vibe.core.concurrency.isWeaklyIsolated
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.