Gabriel Huau schrieb:
Hello,
I would like to know, why the module std.concurrency use function()
parameter in lieu of delegate ?
Delegate would be usefull for example to pass Function Member to
spawn().
Example :
class Foo
{
void test()
{
for(;;)
{
receive(
(string s) { writeln("string"); }
);
}
}
}
void main()
{
Foo l = new Foo();
void delegate() dg;
dg = &l.test;
auto a = spawn(dg);
a.send("test");
}
I have tested and it worked.
Just a guess:
"The general idea is that every messageable entity is represented by a
common handle type (called a Cid in this implementation), which allows
messages to be sent to in-process threads, on-host processes, and
foreign-host processes using the same interface."
(I guess by Cid they mean Tid)
You probably tried this with a thread - which should work fine, because
the delegate's context (which object does it belong to) as accessible
for the other thread.
If the other "logical process" however is a physical process (on the
same or some other machine - i.e. no thread) the context is not available.
Creating a new process with a normal function and its arguments is not a
problem, because all needed context is provided (the function and its
args).