Possible to do receive on a delegate?
John Colvin
john.loughran.colvin at gmail.com
Wed Feb 19 09:04:59 PST 2014
On Wednesday, 19 February 2014 at 16:23:36 UTC, Bienlein wrote:
> 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
delegate
isn't a type. try
int delegate()
instead
More information about the Digitalmars-d-learn
mailing list