Last active
September 13, 2018 01:37
-
-
Save jeffotoni/85beb1d28198bf4c9f2982ac2526ff84 to your computer and use it in GitHub Desktop.
This file contains 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
type DriverPg struct { | |
conn string | |
} | |
var instance *DriverPg | |
func Connect() *DriverPg { | |
instance = &DriverPg{conn: "DriverConnectPostgres"} | |
return instance | |
} | |
func init() { | |
Connect() | |
} | |
func main() { | |
// chamada | |
go func() { | |
time.Sleep(time.Millisecond * 600) | |
fmt.Println(instance.conn) | |
}() | |
go func() { | |
fmt.Println(*Connect()) | |
}() | |
// 100 goroutine | |
for i := 0; i < 100; i++ { | |
go func(ix int) { | |
time.Sleep(time.Millisecond * 60) | |
fmt.Println(ix, " = ", instance.conn) | |
}(i) | |
} | |
fmt.Scanln() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment