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.
Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
September 23 Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
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. |
September 23 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On Saturday, 23 September 2023 at 12:07:38 UTC, Joe 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.
You don’t need a callback for that. It’s done when the download() returns.
|
September 23 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On 23.09.23 14:07, Joe@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
|
September 24 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On Saturday, 23 September 2023 at 12:07:38 UTC, Joe 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. If you want an asynchronous download just create a task or use spawn. Apparently there's also this in vibe: |
September 24 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Elias | On Saturday, 23 September 2023 at 15:09:13 UTC, Elias wrote:
> On Saturday, 23 September 2023 at 12:07:38 UTC, Joe 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.
>
> You don’t need a callback for that. It’s done when the download() returns.
Pretty sure it is not synchronous. I'm running it many times. Maybe it is synchronous and I just didn't notice.
|
September 24 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Köstlin | On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:
> On 23.09.23 14:07, Joe@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).
|
September 24 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On 24.09.23 12:01, Joe@bloow.edu wrote:
> On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:
>> On 23.09.23 14:07, Joe@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
|
September 24 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On 24.09.23 12:01, Joe@bloow.edu wrote: >On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote: >On 23.09.23 14:07, Joe@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). 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, 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). I recommend to use Kind regards, |
September 25 Re: Vibe.d download function, how to get callback when done or error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joe | On 9/23/23 8:07 AM, Joe@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. You might misunderstand how vibe is doing async. Basically, that fiber is put to sleep until the download is finished, and then you get the result. You write your code as if it were synchronous. If you call this outside of an async context, vibe will start up an event loop and run it until your download is done. -Steve |