
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

My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New

As one of my New Year resolutions is to read more tech I’ve decided on an attempt to document my travels in Mannings Modern Java in Actio...
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

To be a more productive reader when rereading a book, it is very convenient to create small rebar3 projects based on books’ samples and i...
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 have read first chapter. Will add my notes / code tries / self exploration as I go along!
Thank you @AstonJ for encouraging to start ...
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

In Aborting Multiple Fetch Requests with One Signal section, the code in abort/abort_ex09.js doesn’t show the downloaded images until Pro...
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

How did a sleepy valley become the epicenter of the technological world as we know it? In the 40th Anniversary Edition of my book, “Charg...
New
Other popular topics

Hello Devtalk World!
Please let us know a little about who you are and where you’re from :nerd_face:
New

SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New

I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me.
I think the Planck and the Preonic (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

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

The File System Access API with Origin Private File System.
WebKit supports new API that makes it possible for web apps to create, open,...
New
New

I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New

zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig.
General-purpose programming language and toolchain for maintaini...
New

This is cool!
DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON
We just witnessed something incredible: the largest open-s...
New
Latest in Journals
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim