anonymous function
A function written inline without a name, often started as a goroutine or passed to another function.
In more detail
Anonymous functions are often passed to other functions or started as background work. One that uses variables from the code around it is called a closure.
Examples
go func(target string) {
defer wait.Done()
fmt.Println(target)
}(name)Go: go func(target string) { ... }(name) starts one as a goroutineRelated terms
- function — A named, reusable block of code that takes inputs, called arguments, and can return a result.
- goroutine — A function running concurrently with the rest of a Go program, started by putting the go keyword before a call.
- defer — A Go statement that schedules a function call to run when the surrounding function returns, used for cleanup such as closing a file.
Taught in
- Goroutines and Concurrent Execution — Concurrent Systems Programming with Go
- Channels and Synchronization — Concurrent Systems Programming with Go
- The select Statement — Concurrent Systems Programming with Go
- Context Cancellation and Timeouts — Concurrent Systems Programming with Go
- Executing Concurrent Checks — Concurrent Systems Programming with Go