# How to implement an asynchronous pipeline with queue

Assume I have three tasks that must be performed in order:

Do[


The three tasks above involve usage of different resources. For example, TaskA imports an image file from disk. TaskB performs some data augmentation via image processing. TaskC sends augmented data to another node via WSTP on TCP.

I would like to improve performance by making a asynchronous pipeline. That is, starting three threads for each task. Each task puts/retrieves intermediate results to/from a queue with fixed size.

(*hypothetical code*)
queueAB = MakeQueue[16];
queueBC = MakeQueue[16];
Do[
EnQueue[queueAB, $$TaskEnded], {taskId, 10000}] ]; taskB = MakeThread[ Module[{productA}, While[True, productA = DeQueue[queueAB]; If[productA ===$$TaskEnded,
EnQueue[queueBC, $$TaskEnded]; Break[], EnQueue[queueBC, TaskB[productA]] ] ] ] ]; taskC = MakeThread[ Module[{productB}, While[True, productB = DeQueue[queueBC]; If[productB ===$$TaskEnded,