Created
June 5, 2019 12:41
-
-
Save sillyfellow/16397d02338f845331993ff55e5da397 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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