Possible to do receive on a delegate?
Bienlein
jeti789 at web.de
Wed Feb 19 08:23:35 PST 2014
Hello,
I was wondering whether it can be done somehow to select on a
delegate in the receive block when spawning a thread:
void spawnedFunc(Tid tid)
{
// Receive a message from the owner thread.
receive(
(int i) { writeln("Received the number ", i);}
(delegate d) { writeln("Receiving a delegate");}
);
}
int delegate() dg;
void main()
{
// Start spawnedFunc in a new thread.
auto tid = spawn(&spawnedFunc, thisTid);
// Send the number 42 to this new thread.
send(tid, 42);
int a = 7;
int foo() { return a + 3; }
dg = &foo;
send(tid, dg);
}
My solution of course doesn't compile.
Thanks for any hint, Bienlein
More information about the Digitalmars-d-learn
mailing list