Is there a way to check if a channel is empty and use this to determine whether to call a subworkflow?

I’m trying to implement a recursive workflow W. It takes as input a channel of items to process A and a channel of immediately processable items B. After calling a process on B, a subset C of members of A become processable, so it calls W(A-B, C).

This works fine, except that I don’t know how to stop the recursion when A is empty. I’d have the same problem even without a recursive workflow.

The reason I’m doing this is because users specify a tree structure in a .csv file which directs a series of merges (i.e. merging technical replicates into biological replicates into conditions). The .csv file has an “id” column and a “from” column which refers to one of the “id” values in another row whose merge outputs are to be used as inputs. This approach lets me process the root of the tree, move one step toward the leaves, process, and repeat until the tree has been traversed.

Thanks for any suggestions on how to address this.