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
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
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
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
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
This is my Journal for readings on Designing Elixir Systems with OTP.
Will post chapter 01 tomorrow! Stay tuned!
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
Hello all.
Creating this space here for general discussion and chat about Powerful Command-Line Applications In Go
In particular, we ca...
New
With Tailwind now the default CSS framework shipped with Phoenix we thought it would be nice to run this book club on the Elixir Forum.
...
New
Other popular topics
A thread that every forum needs!
Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
New
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first:
asdf plugin-upd...
New
Biggest jackpot ever apparently! :upside_down_face:
I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
Author Spotlight
Dmitry Zinoviev
@aqsaqal
Today we’re putting our spotlight on Dmitry Zinoviev, author of Data Science Essentials in ...
New
Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New
Get the comprehensive, insider information you need for Rails 8 with the new edition of this award-winning classic.
Sam Ruby @rubys
...
New
Background
Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /crystal
- /c-plus-plus
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /html
- /opensuse
- /centos
- /php
- /zig
- /deepseek
- /scala
- /lisp
- /textmate
- /sublime-text
- /react-native
- /nixos
- /debian
- /agda
- /kubuntu
- /arch-linux
- /deno
- /django
- /revery
- /ubuntu
- /spring
- /nodejs
- /manjaro
- /diversity
- /lua
- /julia
- /c
- /slackware







