Am I missing with ref in this code?

Paul Backus snarwin at gmail.com
Thu Jan 24 15:49:39 UTC 2019


On Thursday, 24 January 2019 at 15:28:19 UTC, Suliman wrote:
> I am doing very small link-checker. Here is' code 
> https://run.dlang.io/is/p8whrA
>
> I am expecting that on line:
> writefln("url: %s, status: %s", url.url, url.status);
>
> I will print link and it's status. But I am getting only:
> url: http://127.0.0.1:8081/hck, status:
> url: http://127.0.0.1:8081/hck2, status:
> url: http://127.0.0.1:8081/hck3, status:
>
> It's seems that I missed something with refs? Could you help me 
> find error?

It's because runWorkerTask internally passes its arguments along 
to the function by value:

https://github.com/vibe-d/vibe.d/blob/master/core/vibe/core/core.d#L364

The workaround is to pass a pointer instead:

     void getServiceStatus(MyUrl* url) {
         // ...
     }

     // ...

     runWorkerTask(&getServiceStatus, &url);


More information about the Digitalmars-d-learn mailing list