Matching with std.concurrency receive
Adam
Adam at Anizi.com
Fri Dec 9 22:38:19 PST 2011
Okie, having some trouble trying to do matches against classes /
interfaces with templates using the std.concurrency's receive()
function.
Here's a simple use case I have:
import std.stdio;
import std.concurrency;
import std.variant;
immutable interface BasicType {
}
immutable class SubType : BasicType {
}
immutable class A(T : BasicType) {
}
void main() {
Tid tid = spawn(&thread);
immutable A!(SubType) instance = new immutable(A!(SubType))();
send(tid, instance);
while (true) {}
}
void thread() {
receive(
(A!(BasicType) message)
{
writeln("Received");
},
(Variant ant)
{
writeln(ant.type());
}
);
}
Running this outputs the Variant ant's type, so we see that it
"falls through" to that pattern. However, if I switch the match from
BasicType to SubType... it just hangs on me.
What horribly stupid thing am I doing here?
More information about the Digitalmars-d-learn
mailing list