Hi all,
I’m working on a larger workflow and have encountered a challenge. Here’s the scenario:
I have a channel v1, which may sometimes be empty. In that case, I want to assign another channel sample (holding [SNP-2024-FT]) to v1. However, if v1 is not empty, it should retain its original value.
Here’s the code snippet I tried:
groovy
params.sampleId = "SNP-2024-FT"
workflow {
input_ch = Channel.of(
tuple(params.sampleId)
)
sample = input_ch.map { it -> [it[0]] }
sample.view()
v1 = Channel.empty().ifEmpty(true).map { value ->
if (value == true) {
sample
} else {
value
}
}
v1.view()
}
The issue is that this gives the error: DataflowBroadcast around DataflowStream[?]
. It seems related to the fact that sample is itself a channel, not a static value, and the ifEmpty(true)
only works with direct static values.
Additionally, consider that Channel.empty() is an empty output channel from a process in this context, so the behavior of assigning it can be tricky. When I set a direct value like ifEmpty("some value")
, it works, but since sample is an output channel, it’s always a channel rather than a direct value.
Does anyone know how to work around this or handle such cases? Any advice or alternative approaches would be greatly appreciated!
Thanks in advance!