<p>So from this page...
<a href="https://groups.google.com/g/nextflow/c/jt77_-uApMs" rel="nofollow noreferrer">https://groups.google.com/g/nextflow/c/jt77_-uApMs</a></p>
<p>It is the &quot;scatter-gather&quot; pattern. I think the answer is to collect() the channel as follows - interested to hear if there is a better way</p>
<pre><code>files = Channel.from params.the_files_list

process process_files {

    input:
    val file_path from files

    output:
    stdout result

    &quot;&quot;&quot;
    python ./process_one_file.py $file_path
    &quot;&quot;&quot;
}

process merge_results {
    
    input:
    val go from result.collect()

    script:
    &quot;&quot;&quot;
    echo &quot;Triggered once after all files complete!&quot;
    &quot;&quot;&quot;
        
}
</code></pre>

CC BY-SA 4.0
2021-04-07T09:45:23.283Z
`.collect()` is the correct way to do this
Pallie
CC BY-SA 4.0
2021-04-07T09:28:36.203Z
2021-04-07T09:28:36.203Z
Brendan Hill
<p>Simple question but I am stumped. (I am still learning Nextflow)</p>
<p>I have a process which takes as input a channel of files and processes each file separately.</p>
<p>There is a second process which needs to wait until all files are complete, so it can merge the outputs into a single collated file.</p>
<p>How can I do this? I have tried subscribing to &quot;onComplete&quot; event to no avail as I cannot specify a process as the function to trigger.</p>
<pre><code>
files = Channel.from params.the_files_list

process process_files {

    input:
    val file_path from files

    output:
    stdout result

    &quot;&quot;&quot;
    python ./process_one_file.py $file_path
    &quot;&quot;&quot;
}

process merge_results {
    
    input:
    ????

    output:
    ????

    script:
    &quot;&quot;&quot;
    echo &quot;How to trigger this process once, after all individual files are processed?&quot;
    &quot;&quot;&quot;
        
}

??? Want to do something like this
result.subscribe onComplete: merge_results

<span class="math-container">```</span>
</code></pre>

CC BY-SA 4.0
2022-05-30T21:59:06.200Z
I've run into the same problem but I'm interested in trying this method. Did it work for you?
daray
<nextflow><workflow-management>
How to trigger next process on completion of previous process?
# How to trigger next process on completion of previous process?

(Asked by: username_0 on 2021-04-07)

Simple question but I am stumped. (I am still learning Nextflow)
I have a process which takes as input a channel of files and processes each file separately.
There is a second process which needs to wait until all files are complete, so it can merge the outputs into a single collated file.
How can I do this? I have tried subscribing to "onComplete" event to no avail as I cannot specify a process as the function to trigger.

files = Channel.from params.the_files_list

process process_files {

    input:
    val file_path from files

    output:
    stdout result

    """
    python ./process_one_file.py $file_path
    """
}

process merge_results {
    
    input:
    ????

    output:
    ????

    script:
    """
    echo "How to trigger this process once, after all individual files are processed?"
    """
        
}

??? Want to do something like this
result.subscribe onComplete: merge_results

```

**Tags:** nextflow, workflow-management
> **Comments:**
> **username_1**: I've run into the same problem but I'm interested in trying this method. Did it work for you?  

---

## 1 answers

### Answer by username_0 on 2021-04-07. Score: 2 | Accepted answer

So from this page...
https://groups.google.com/g/nextflow/c/jt77_-uApMs
It is the "scatter-gather" pattern. I think the answer is to collect() the channel as follows - interested to hear if there is a better way
files = Channel.from params.the_files_list

process process_files {

    input:
    val file_path from files

    output:
    stdout result

    """
    python ./process_one_file.py $file_path
    """
}

process merge_results {
    
    input:
    val go from result.collect()

    script:
    """
    echo "Triggered once after all files complete!"
    """
        
}

> **Comments:**
> **username_2**: `.collect()` is the correct way to do this  

---

