Vibe.d download function, how to get callback when done or error?

Christian Köstlin christian.koestlin at gmail.com
Sun Sep 24 12:05:35 UTC 2023


On 24.09.23 12:01, Joe at bloow.edu wrote:
> On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:
>> On 23.09.23 14:07, Joe at bloow.edu wrote:
>>> I'm using download(url, filename) to download files in vibe.d.
>>>
>>> The issue is that I do not know when the download is finished or 
>>> errors. There is a callback for the streaming side but not for the 
>>> file download.
>>>
>> A small test program shows, that if the function return normally the 
>> transfer was done (and the file saved).
>> The function raises an exception if there is e,g, an http error status 
>> communicated.
>>
>> I am not sure what happens if the download is interrupted in the 
>> middle. I guess there will be an exception, but the file might be 
>> written partially.
>>
>>
>>
>> Kind regards,
>> Christian
> 
> I can't do any testing because overnight for no explicable reason the 
> app will not compile any more.
> 
> If it is synchronous then I should be able to do what I need without 
> issue. When I initially was using it and the way the app works it seemed 
> like it was running in parallel because I didn't see it execute 
> synchronously because the tasks were relatively short and I just thought 
> it was asynchronous for some reason(I didn't give it any thought at the 
> time until I got errors in the download and needed to make the code more 
> robust but I can't do anything until I figure out why the code no longer 
> compiles(I made a post about it but it's not showing up yet).
minimal program to test the behavior (although with fibers it might be 
tricky to see whats really going on .. perhaps try to do two downloads 
after each other and see how the program behaves):


```d
import vibe.vibe;
import std.stdio : writeln;

void main(string[] args)
{
     try {
     download(args[1], args[2]);
     } catch (Exception e)
     {
         writeln("puh: ", e);
     }
}
```

Kind regards,
Christian


More information about the Digitalmars-d-learn mailing list