RejectedSoftware Forums

Sign up

vibe.core.concurrency.async with args example?

Hi!

How to call function with arguments from async()?

For example, trying to pass variable "conn" of type "Connection":

auto r = async((Connection c){ return c.waitEndOf(type, timeout); }, conn);

causes error:

../../.dub/packages/vibe-d-0.7.27/source/vibe/core/concurrency.d(1140,23): Error: template vibe.core.core.runTask cannot deduce function from argument types !()(void function(FreeListRef!(shared(bool), true) dst, bool delegate(Connection) @safe callable, Connection param2) @system, FreeListRef!(shared(bool), true), bool delegate(Connection) @safe, Connection), candidates are:
../../.dub/packages/vibe-d-0.7.27/source/vibe/core/core.d(178,6): vibe.core.core.runTask(ARGS...)(void delegate(ARGS) task, ARGS args)
../../.dub/packages/vibe-d-0.7.27/source/vibe/core/concurrency.d(1127,30): Error: function vibe.core.concurrency.async!(bool delegate(Connection) @safe, Connection).async no return exp; or assert(0); at end of function
source/vibe/db/postgresql/package.d(249,19): Error: template instance vibe.core.concurrency.async!(bool delegate(Connection) @safe, Connection) error instantiating
dmd failed with exit code 1.

Re: vibe.core.concurrency.async with args example?

On Wed, 24 Feb 2016 09:30:08 GMT, denizzzka wrote:

Hi!

How to call function with arguments from async()?

For example, trying to pass variable "conn" of type "Connection":

auto r = async((Connection c){ return c.waitEndOf(type, timeout); }, conn);

causes error:

../../.dub/packages/vibe-d-0.7.27/source/vibe/core/concurrency.d(1140,23): Error: template vibe.core.core.runTask cannot deduce function from argument types !()(void function(FreeListRef!(shared(bool), true) dst, bool delegate(Connection) @safe callable, Connection param2) @system, FreeListRef!(shared(bool), true), bool delegate(Connection) @safe, Connection), candidates are:
../../.dub/packages/vibe-d-0.7.27/source/vibe/core/core.d(178,6): vibe.core.core.runTask(ARGS...)(void delegate(ARGS) task, ARGS args)
../../.dub/packages/vibe-d-0.7.27/source/vibe/core/concurrency.d(1127,30): Error: function vibe.core.concurrency.async!(bool delegate(Connection) @safe, Connection).async no return exp; or assert(0); at end of function
source/vibe/db/postgresql/package.d(249,19): Error: template instance vibe.core.concurrency.async!(bool delegate(Connection) @safe, Connection) error instantiating
dmd failed with exit code 1.

I've fixed the error on master: a8faddf

The problem was that the non-shared (using runTask for concurrency) path wasn't tested, only the shared one (using runWorkerTask).

Re: vibe.core.concurrency.async with args example?

Some issue with async again:

        import vibe.core.concurrency;
 
        auto future = async({
            immutable ubyte b = 1;
            return b;
        });

causes:

/usr/include/dmd/druntime/import/object.d(2876,5): Error: cannot modify immutable expression obj
../../.dub/packages/vibe-d-0.7.28/source/vibe/utils/memory.d(652,37): Error: template instance object.destroy!(immutable(ubyte)) error instantiating
../../.dub/packages/vibe-d-0.7.28/source/vibe/utils/memory.d(678,19): instantiated from here: FreeListObjectAlloc!(immutable(ubyte), true, true, int)
../../.dub/packages/vibe-d-0.7.28/source/vibe/core/concurrency.d(1080,3): instantiated from here: FreeListRef!(immutable(ubyte), true)
../../.dub/packages/vibe-d-0.7.28/source/vibe/core/concurrency.d(1127,1): instantiated from here: Future!(immutable(ubyte))
source/vibe/db/postgresql/package.d(345,28): instantiated from here: async!(immutable(ubyte) function() pure nothrow @nogc @safe, )
dmd failed with exit code 1.

Re: vibe.core.concurrency.async with args example?

On Sun, 20 Mar 2016 13:44:42 GMT, denizzzka wrote:

Some issue with async again:

Reasons for this I understand. But can something be done about it? Immutable values very usable for multithreading.

Re: vibe.core.concurrency.async with args example?

On Sun, 20 Mar 2016 15:12:17 GMT, denizzzka wrote:

On Sun, 20 Mar 2016 13:44:42 GMT, denizzzka wrote:

Some issue with async again:

Reasons for this I understand. But can something be done about it? Immutable values very usable for multithreading.

Fixed by 402fb81. Unfortunately there seems to be no equivalent to StripHeadConst in Phobos, although it should be a quite common operation.