Skip to content

Instantly share code, notes, and snippets.

@sillyfellow
Created June 5, 2019 12:41
Show Gist options
  • Save sillyfellow/16397d02338f845331993ff55e5da397 to your computer and use it in GitHub Desktop.
Save sillyfellow/16397d02338f845331993ff55e5da397 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func HandlerCreator() func() {
timer := func() func() {
fmt.Println("Initiating timer")
t := time.Now()
return func() {
fmt.Printf("Time spent is: %v\n", time.Now().Sub(t))
}
}
return func() {
defer timer()()
fmt.Println("Handling stuff")
time.Sleep(2 * time.Second)
}
}
func main() {
handler := HandlerCreator()
handler()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment