Referance usage in async function

kerdemdemir kerdemdemir at gmail.com
Sat Nov 30 13:45:00 UTC 2019


I have simplified my problem which can be seen below.

import std.stdio;
import vibe.core.core;
import vibe.core.concurrency;
import vibe.data.json;

void main()
{
     int[] list;

     bool ListManipulator(ref int[] list)
     {
         list ~= 2;
         list ~= 4;
         return true;
     }

     bool ListManipulatorPointer( int[]* list)
     {
         *list ~= 2;
         *list ~= 4;
         return true;
     }


     auto future = vibe.core.concurrency.async(&ListManipulator, 
list);
     future.getResult();

     writeln(list); ----> prints empty list

     future = vibe.core.concurrency.async(&ListManipulatorPointer, 
&list);
     future.getResult();

     writeln(list); ----> prints [2,4]
}


Why passing the pointer works meanwhile passing as reference does 
nothing? I feel that is more D issue than vibe.d which I can 
learn something I hope.

Erdem





More information about the Digitalmars-d-learn mailing list