On Thursday, 18 October 2012 at 06:30:08 UTC, Joshua Niehus wrote:
Is the following snippet a bug?
---
import core.thread;
import std.stdio, std.concurrency;
void foo(Tid tid) {
send(tid, true);
}
void main() {
auto fooTid = spawn(&foo, thisTid);
auto receiveInt = receiveTimeout(dur!"seconds"(10), (int
isInt) {
writeln("I should not be here");
});
}
// output: "I should not be here"
---
If not, is there some way I could achieve
"receiveOnlyTimeout!(int)(dur, fun);" ?
Thanks,
Josh
I can't see the bug? The receiver accepts a bool as an int, same
way a normal function does. The timeout is long enough that foo
gets a chance to send. If you want to stop the int receiver
getting a bool, you could add another receiver with (bool) { //
do nothing } or whatever before the (int) one, which will be a
better match for the send.