'Groovy's Path.traverse() extension, IntelliJ idea syntactic error
I am editing a Groovy (3.0.10) script and I am getting a syntactic error that I do not understand:
When I try this in GroovyConsole, it seems to work just fine.
Why is IntelliJ IDEA complaining? This is with IntelliJ IDEA 2022.1.1.
The snippet in text:
final java.nio.file.Path p;
p.traverse(type: FileType.FILES, nameFilter: ~/^\.deployment$/, maxDepth: 1) { final Path dotDeploymentPath ->
println dotDeploymentPath
}
UPDATE 1
I actually got the same error from Groovy when running the script in our product:
Script4.groovy: 59: [Static type checking] - Cannot call java.nio.file.Path#traverse(java.util.Map <java.lang.String, java.lang.Object>, groovy.lang.Closure) with arguments [java.util.LinkedHashMap <java.lang.String, java.io.Serializable>, groovy.lang.Closure]
@ line 59, column 9.
extensionsPath.traverse(type: FileType.FILES, nameFilter: ~/^\.deployment$/, maxDepth: 1) { final Path dotDeploymentPath ->
^
UPDATE 2
I ended up with this which seems to work just fine. I still don't understand why Groovy does not like the options as arguments of the call.
def final traverseOptions = [type: FileType.FILES, nameFilter: ~/^\.deployment$/, maxDepth: 1] as Map<String, Object>;
extensionsPath.traverse(traverseOptions) { final Path dotDeploymentPath ->
Solution 1:[1]
To ensure sequential execution of functions, run the functions in a single goroutine:
go func() {
func1()
func2()
}()
Solution 2:[2]
If you really want them as separate goroutines (why?) you need to synchronize them. You can use channels, mutexes, or other concurrency primitives. The example below accomplishes that with a signaling channel:
ch := make(chan struct{})
go func() {
func1()
close(ch)
}
go func() {
<-ch
func2()
}
Playground: https://go.dev/play/p/ZqHz-ILpA2J
EDIT: Following Paul Hankin's advice, using close(ch) instead of ch <- struct{}{} to signal completion.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bayta Darell |
| Solution 2 |

