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

2023-09-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/23/23 8:07 AM, j...@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


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

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn

On 24.09.23 12:01, j...@bloow.edu wrote:

On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:

On 23.09.23 14:07, j...@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).




I recommend to use
`https://httpbin.org/drip?duration=20&numbytes=100&code=200&delay=0` as 
url to test vibes download.


Kind regards,
Christian



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

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn

On 24.09.23 12:01, j...@bloow.edu wrote:

On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:

On 23.09.23 14:07, j...@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


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

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin 
wrote:

On 23.09.23 14:07, j...@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).





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

2023-09-24 Thread Joe--- via Digitalmars-d-learn

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.




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

2023-09-24 Thread Imperatorn via Digitalmars-d-learn

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:

https://vibed.org/api/vibe.core.concurrency/async


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

2023-09-23 Thread Christian Köstlin via Digitalmars-d-learn

On 23.09.23 14:07, j...@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



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

2023-09-23 Thread Elias via Digitalmars-d-learn

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.


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

2023-09-23 Thread Joe--- via Digitalmars-d-learn

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.