Client side async

What I’m trying to do:

Download images client side in parallel. My page has to fetch many images dynamically. I’m trying to fetch a list of many of them in parallel on client in anvil. Would like to do it asyncio style so that other anvil code will not get blocked by the image fetches.

What I’ve tried and what’s not working:

Tried looking for docs and/or asyncio module support on client. Cannot see anything.

1 Like

This project seems to have async/await stuff working, just putting it out there. I know it can’t be used 1 to 1, but maybe provide some ideas on async? Pyodide — Version 0.18.0

What do you mean by download image client side?
Download many image files to the user’s file system?
Or render them on the browser?

1 Like

Hi, my page has many images to display. The images are in a private s3 bucket for which there are no direct urls. So my client sends image name to anvil server, anvil server uses python boto3 s3 client to fetch image bytes, and pass it back to client page. The bytes client gets from anvil server call, it then assigns as imageview.source = response. I need to do this for many images, ideally in parallel. While it does this I want other anvil code to run too, not block and wait for all images to complete.

What about running a bunch of background tasks, one per image, that download the images and store them in an Media column in a table?

Perhaps here there is the risk that the client could try to get the image before it’s available. I don’t know if Anvil would automatically take care of this or if you need to invent some trick.

If you need a trick, you could have a timer on the client side that asks the server if the images are ready, and set the source only then.

2 Likes

I will investigate background tasks some more, thanks for the pointers.

1 Like