Step 4 - How map
is synchronous
An illustrative test is one where we do not use a process
for the execution, but rather just map
but such that one of the inputs takes longer to process, i.e.:
// Step - 4
def waitAndReturn(it) { sleep(2000); return it }
workflow step4 {
Channel.from( [ 1, 2, 3 ] ) \
| map{ (it == 2) ? waitAndReturn(it) : it } \
| map{ it + 1 } \
| view{ it }
}
Running it:
> nextflow -q run . -entry step4
WARN: DSL 2 IS AN EXPERIMENTAL FEATURE UNDER DEVELOPMENT -- SYNTAX MAY CHANGE IN FUTURE RELEASE
2
3
4
The result may be somewhat unexpected, the order is retained even though there’s a 2 second delay between the first entry and the rest. The sleep
in other words blocks all the parallel execution branches.
This is a clear indication of why it’s better to use a process
to execute computations. On the other hand, as long as we stay inside the map
and don’t run a process
, the order is retained. This opens up possibilities that we will exploit in what follows.