Created
June 25, 2019 06:09
-
-
Save hosszukalman/92ff20f9e0c252bffc74521bb6157eed 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 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