Menu

1 / 4

The Cleanup Bug Hiding Behind Promise.all

JavaScript in Plain English - Medium·Ferid Brković·2 days ago
#RQfie6Lp
Reading 0:00
15s threshold

Member-only story

JavaScriptWeb DevelopmentSoftware Development The Cleanup Bug Hiding Behind Promise.all

Ferid Brković

5 min read1 hour ago

Press enter or click to view image in full size

A rejected batch can leave other tasks running. Wait for their actual completion before removing the resources they still need.

A test starts two jobs in a temporary workspace. One fails. The test catches the error, deletes the workspace, and moves on.

The other job is still writing to it.

That is a possible outcome of putting cleanup after await Promise.all(...) . The await has finished, but the work represented by its input promises may not have finished with it.

This is easy to miss because the successful path behaves exactly as you expect: every job completes before you continue.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.