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
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
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
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
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
With Phoenix and LiveView having recently had a fairly major release, and Programming Phoenix LiveView being updated too, we thought it w...
New
Learning Domain-Driven Design
Building software is harder than ever. As a developer, you not only have to chase ever-changing technologic...
New
https://fs.blog/mental-models/
I’ve been reading Farnham Street for a while, and this topic is the recommended starting point for new re...
New
Other popular topics
Brace yourself for a fun challenge: build a photorealistic 3D renderer from scratch! In just a couple of weeks, build a ray tracer that r...
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
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face:
Perhaps if there’s enough peop...
New
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
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
Author Spotlight
Dmitry Zinoviev
@aqsaqal
Today we’re putting our spotlight on Dmitry Zinoviev, author of Data Science Essentials in ...
New
Author Spotlight:
Bruce Tate
@redrapids
Programming languages always emerge out of need, and if that’s not always true, they’re defin...
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
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /html
- /centos
- /php
- /zig
- /deepseek
- /scala
- /sublime-text
- /lisp
- /textmate
- /react-native
- /nixos
- /debian
- /agda
- /kubuntu
- /arch-linux
- /deno
- /django
- /revery
- /ubuntu
- /manjaro
- /spring
- /nodejs
- /diversity
- /lua
- /julia
- /slackware
- /c







