digitalmars.D.learn - Vibe.d download function, how to get callback when done or error?
- Joe bloow.edu (4/4) Sep 23 2023 I'm using download(url, filename) to download files in vibe.d.
- Elias (3/7) Sep 23 2023 You don’t need a callback for that. It’s done when the download()
- Joe bloow.edu (3/11) Sep 24 2023 Pretty sure it is not synchronous. I'm running it many times.
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (9/14) Sep 23 2023 A small test program shows, that if the function return normally the
- Joe bloow.edu (13/29) Sep 24 2023 I can't do any testing because overnight for no explicable reason
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (19/52) Sep 24 2023 minimal program to test the behavior (although with fibers it might be
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (6/41) Sep 24 2023 I recommend to use
- Imperatorn (4/8) Sep 24 2023 If you want an asynchronous download just create a task or use
- Steven Schveighoffer (7/12) Sep 25 2023 You might misunderstand how vibe is doing async. Basically, that fiber
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.
Sep 23 2023
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.
Sep 23 2023
On Saturday, 23 September 2023 at 15:09:13 UTC, Elias wrote:On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote:Pretty sure it is not synchronous. I'm running it many times. Maybe it is synchronous and I just didn't notice.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.
Sep 24 2023
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
Sep 23 2023
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 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'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
Sep 24 2023
On 24.09.23 12:01, Joe bloow.edu wrote:On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote: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, ChristianOn 23.09.23 14:07, Joe bloow.edu wrote: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'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
Sep 24 2023
On 24.09.23 12:01, Joe bloow.edu wrote:On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:I recommend to use `https://httpbin.org/drip?duration=20&numbytes=100&code=200&delay=0` as url to test vibes download. Kind regards, ChristianOn 23.09.23 14:07, Joe bloow.edu wrote: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'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
Sep 24 2023
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
Sep 24 2023
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
Sep 25 2023