Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
Created June 25, 2019 06:09
Show Gist options
  • Save hosszukalman/92ff20f9e0c252bffc74521bb6157eed to your computer and use it in GitHub Desktop.
Save hosszukalman/92ff20f9e0c252bffc74521bb6157eed to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func Start() (f Foo) {
fmt.Println("start with type")
return
}
type Foo struct{}
func (f Foo) Stop() {
fmt.Println("stop with type")
}
func StartAndStop() func() {
fmt.Println("start with closure")
return func() {
fmt.Println("stop with closure")
}
}
func main() {
defer Start().Stop()
defer StartAndStop()()
f := Start()
defer f.Stop()
time.Sleep(2 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment