Suppose we need to save a collection of images from the web. We have a list of image addresses, and a program will download each image to a file. We’ll follow what the program does, how it limits unfinished downloads, and how it uses network waiting time to make progress.
Follow one image download
Start with the work needed to download one image.
Start with image A. The program knows where to request the image and where it should save the file. It asks the remote server to send the image’s data.
Sending the request does not put the complete image in our file immediately. The server has to respond, and the data has to travel over the network. During part of that time, there may be no image data available for our program to handle.
That is what waiting means in this example: the program has an unfinished download, but its next step depends on data that has not arrived yet. The program cannot finish saving A until it receives that data.
The data can arrive in pieces. The program receives some bytes, saves the part it has received, then may wait for the next piece. Waiting and receiving can repeat several times during one download.
For this example, A’s download is complete only when the entire image has arrived and the program has finished saving its file. Receiving the first piece is progress, but the download is still unfinished.
We’ll call the running program that carries out this work a worker. Downloading one image is one job for that worker. The job includes the whole sequence: making the request, waiting, receiving the data and saving the complete file.
While A is unfinished, the worker keeps a record of its progress. That record lets it associate incoming data with A and continue saving the right file.