
ggarnier
Modern Asynchronous JavaScript: displaying images as they're loaded (page 50)
In Aborting Multiple Fetch Requests with One Signal
section, the code in abort/abort_ex09.js
doesn’t show the downloaded images until Promise.all
fulfills, which means you need to wait for all the image downloads before seeing them. Also, if you cancel after some downloads have finished, you won’t see those images.
I suggest a small change to make it display the images as the corresponding promise fulfills:
33c33,38
< const tasks = urls.map(url => fetch(url, {signal: controller.signal}));
---
> const tasks = urls.map(url => fetch(url, {signal: controller.signal}).then(async (r) => {
> const img = document.createElement('img');
> const blob = await r.blob();
> img.src = URL.createObjectURL(blob);
> gallery.appendChild(img);
> }));
36,43c41,43
< const response = await Promise.all(tasks);
< response.forEach(async (r) => {
< const img = document.createElement('img');
< const blob = await r.blob();
< img.src = URL.createObjectURL(blob);
< gallery.appendChild(img);
< });
< result.textContent = '';
---
> Promise.all(tasks).then(() => {
> result.textContent = '';
> });
Marked As Solved

Faraz
Author of Modern Asynchronous JavaScript
Oh, my bad! Thanks for clarifying that. We’re updating the code in the next version of the book.
Popular Community topics

So I have enough money to last a year. Realistically I’m still going to have to work part time painting. I’m so done with it though!
I h...
New

Concurrent Data Processing in Elixir is now content complete and I finally found the time I’ve been looking for to dedicate behind readin...
New

I am going to dump my thoughts, methods, codes, experiences and rants while learning OCaml into this thread.
This is probably the 5th or...
New

The very first time I’ve seen a line of Elixir I was in awe. Coming from Ruby the syntax was familiar.
But I wanted to know what was thi...
New

TL;DR I am reading “Domain Modeling Made Functional” and discussing and keeping a journal of what I learned from it, any co-readers welco...
New

I would love to begin a book club with Mike Amundsen’s (@mamund) book
Design and Build Great Web APIs.
It seems that building new syste...
New

This is my Journal for readings on Designing Elixir Systems with OTP.
Will post chapter 01 tomorrow! Stay tuned!
New

Agile Web Development with Rails 6 Chapter 11. Task F
Currently reading and working through AWDR6 by Sam Ruby, David Bryant Copeland, a...
New

With AI set to play a big role in our industry Elixir users are lucky to have Nx, so we’re running our Nx related book club on Genetic Al...
New

When the pandemic, heart disease, and personal tragedy threatened to steal everything the Tates spent years building, they found hope, he...
New
Other popular topics

What chair do you have while working… and why?
Is there a ‘best’ type of chair or working position for developers?
New

I’m thinking of buying a monitor that I can rotate to use as a vertical monitor?
Also, I want to know if someone is using it for program...
New

No chair. I have a standing desk.
This post was split into a dedicated thread from our thread about chairs :slight_smile:
New

Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New

I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl:
The Ser...
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New

Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New

Author Spotlight:
Karl Stolley
@karlstolley
Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

Author Spotlight:
Tammy Coron
@Paradox927
Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /textmate
- /sublime-text
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /django
- /manjaro
- /spring
- /diversity
- /nodejs
- /lua
- /c
- /slackware
- /julia
- /neovim