This website works better with JavaScript.
Home
Help
Sign In
hackerbots
/
server
Watch
1
Star
0
Fork
0
Code
Issues
2
Pull Requests
0
Activity
Browse Source
Don't automatically do concurrency for users
http://talks.golang.org/2013/bestpractices.slide#25
master
Stephen McQuay
6 years ago
parent
0d11b8a0ba
commit
8b52f93ca5
2 changed files
with
11 additions
and
9 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+10
-9
id.go
+1
-0
id_test.go
+ 10
- 9
id.go
View File
@ -18,15 +18,16 @@ type IdGenerator struct {
}
func
NewIdGenerator
(
)
*
IdGenerator
{
g
:=
IdGenerator
{
}
g
.
id
=
make
(
chan
int64
)
go
func
(
)
{
var
i
int64
for
i
=
0
;
;
i
++
{
g
.
id
<-
i
}
}
(
)
return
&
g
return
&
IdGenerator
{
id
:
make
(
chan
int64
)
,
}
}
func
(
idg
*
IdGenerator
)
Run
(
)
{
var
i
int64
for
i
=
0
;
;
i
++
{
idg
.
id
<-
i
}
}
func
(
id
*
IdGenerator
)
Hash
(
)
string
{
+ 1
- 0
id_test.go
View File
@ -8,6 +8,7 @@ func TestIDGenerator(t *testing.T) {
cache
:=
make
(
map
[
string
]
bool
)
var
cur
string
gg
:=
NewIdGenerator
(
)
go
gg
.
Run
(
)
for
i
:=
0
;
i
<
10000
;
i
++
{
cur
=
gg
.
Hash
(
)
if
_
,
ok
:=
cache
[
cur
]
;
ok
{
Write
Preview
Loading…
Cancel
Save