www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.concurrency.receive() question

reply "Ruslan Mullakhmetov" <nobody example.com> writes:
i try to compile the following slightly modified sample from the 
book and it failed with the following messages

======= source ============

import std.stdio;
import std.concurrency;

void fileWriter()
	// Write loop
	for (bool running = true; running; )
			(immutable(ubyte)[] buffer) {},
			(OwnerTerminated) { running = false; }
	stderr.writeln("Normally terminated.");

void main()

====== error messages =======

/Users/ruslan/Source/dlang/dub-test/source/listener.d(11): Error: 
template std.concurrency.receive does not match any function 
template declaration. Candidates are:
        std.concurrency.receive(T...)(T ops)
/Users/ruslan/Source/dlang/dub-test/source/listener.d(11): Error: 
template std.concurrency.receive(T...)(T ops) cannot deduce 
template function from argument types !()(void 
function(immutable(ubyte)[] buffer) pure nothrow  safe, void)


what's wrong? if i replace OwnerTerminated with int or simply 
remove everything is ok.

if i replace with my own struct Terminate - fail.

any help would be appreciated.
Aug 11 2013
parent "David Nadlinger" <code klickverbot.at> writes:
Hi Ruslan,

On Sunday, 11 August 2013 at 13:04:41 UTC, Ruslan Mullakhmetov 
 (OwnerTerminated) { running = false; }

This is a template function literal taking an argument named "OwnerTerminated", not a function with an unnamed parameter of type OwnerTerminated. Quite a sublime trap, admittedly. In the future you might want to post similar questions to the digitalmars.D.learn group instead. Hope this helps, David
Aug 11 2013