-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
0014db9
commit 2b4c5b3
Showing
4 changed files
with
135 additions
and
14 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
modules/nextflow/src/main/groovy/nextflow/extension/LastOp.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.extension | ||
|
||
|
||
import groovy.transform.CompileStatic | ||
import groovyx.gpars.dataflow.DataflowReadChannel | ||
import groovyx.gpars.dataflow.DataflowVariable | ||
import groovyx.gpars.dataflow.operator.DataflowProcessor | ||
import nextflow.extension.op.Op | ||
|
||
/** | ||
* Implements last operator | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@CompileStatic | ||
class LastOp { | ||
|
||
private DataflowReadChannel source | ||
private DataflowVariable target | ||
|
||
LastOp withSource(DataflowReadChannel source) { | ||
assert source!=null | ||
this.source = source | ||
return this | ||
} | ||
|
||
LastOp withTarget(DataflowVariable target) { | ||
assert target!=null | ||
this.target = target | ||
return this | ||
} | ||
|
||
DataflowVariable apply() { | ||
assert source!=null | ||
if( target==null ) | ||
target = new DataflowVariable() | ||
|
||
def last = null | ||
final next = { last = it } | ||
final done = { DataflowProcessor proc -> Op.bind(proc, target, last) } | ||
DataflowHelper.subscribeImpl( source, [onNext:next, onComplete: done] ) | ||
return target | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,15 @@ import groovy.transform.CompileStatic | |
import groovy.util.logging.Slf4j | ||
import groovyx.gpars.dataflow.DataflowReadChannel | ||
import groovyx.gpars.dataflow.DataflowWriteChannel | ||
import groovyx.gpars.dataflow.operator.ChainWithClosure | ||
import groovyx.gpars.dataflow.operator.CopyChannelsClosure | ||
import groovyx.gpars.dataflow.operator.DataflowEventAdapter | ||
import groovyx.gpars.dataflow.operator.DataflowProcessor | ||
import nextflow.Channel | ||
import nextflow.Global | ||
import nextflow.Session | ||
import nextflow.extension.op.Op | ||
|
||
/** | ||
* Implement "take" operator | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
|
@@ -73,11 +73,16 @@ class TakeOp { | |
} | ||
} | ||
|
||
newOperator( | ||
inputs: [source], | ||
outputs: [target], | ||
listeners: (length > 0 ? [listener] : []), | ||
new ChainWithClosure(new CopyChannelsClosure())) | ||
final params = new OpParams() | ||
.withInput(source) | ||
.withOutput(target) | ||
if( length>0 ) | ||
params.withListener(listener) | ||
|
||
newOperator(params) { | ||
final proc = getDelegate() as DataflowProcessor | ||
Op.bind(proc, target, it) | ||
} | ||
|
||
return target | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters