Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
a06ff797
Commit
a06ff797
authored
Jun 25, 2019
by
wongoo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unused code
parent
971212c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
20 deletions
+11
-20
wheel.go
time/wheel.go
+1
-6
wheel_test.go
time/wheel_test.go
+10
-14
No files found.
time/wheel.go
View file @
a06ff797
...
@@ -39,19 +39,16 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
...
@@ -39,19 +39,16 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
period
:
span
*
(
time
.
Duration
(
buckets
)),
period
:
span
*
(
time
.
Duration
(
buckets
)),
ticker
:
time
.
NewTicker
(
span
),
ticker
:
time
.
NewTicker
(
span
),
index
:
0
,
index
:
0
,
ring
:
make
([]
(
chan
struct
{})
,
buckets
),
ring
:
make
([]
chan
struct
{}
,
buckets
),
now
:
time
.
Now
(),
now
:
time
.
Now
(),
}
}
go
func
()
{
go
func
()
{
var
notify
chan
struct
{}
var
notify
chan
struct
{}
// var cw CountWatch
// cw.Start()
for
t
:=
range
w
.
ticker
.
C
{
for
t
:=
range
w
.
ticker
.
C
{
w
.
Lock
()
w
.
Lock
()
w
.
now
=
t
w
.
now
=
t
// fmt.Println("index:", w.index, ", value:", w.bitmap.Get(w.index))
notify
=
w
.
ring
[
w
.
index
]
notify
=
w
.
ring
[
w
.
index
]
w
.
ring
[
w
.
index
]
=
nil
w
.
ring
[
w
.
index
]
=
nil
w
.
index
=
(
w
.
index
+
1
)
%
len
(
w
.
ring
)
w
.
index
=
(
w
.
index
+
1
)
%
len
(
w
.
ring
)
...
@@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
...
@@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
close
(
notify
)
close
(
notify
)
}
}
}
}
// fmt.Println("timer costs:", cw.Count()/1e9, "s")
}()
}()
return
w
return
w
...
@@ -87,7 +83,6 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} {
...
@@ -87,7 +83,6 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} {
if
w
.
ring
[
pos
]
==
nil
{
if
w
.
ring
[
pos
]
==
nil
{
w
.
ring
[
pos
]
=
make
(
chan
struct
{})
w
.
ring
[
pos
]
=
make
(
chan
struct
{})
}
}
// fmt.Println("pos:", pos)
c
:=
w
.
ring
[
pos
]
c
:=
w
.
ring
[
pos
]
w
.
Unlock
()
w
.
Unlock
()
...
...
time/wheel_test.go
View file @
a06ff797
...
@@ -24,13 +24,11 @@ func TestWheel(t *testing.T) {
...
@@ -24,13 +24,11 @@ func TestWheel(t *testing.T) {
cw
.
Start
()
cw
.
Start
()
for
{
for
{
select
{
<-
wheel
.
After
(
TimeMillisecondDuration
(
1000
))
case
<-
wheel
.
After
(
TimeMillisecondDuration
(
1000
))
:
fmt
.
Println
(
"loop:"
,
index
)
fmt
.
Println
(
"loop:"
,
index
)
index
++
index
++
if
index
>=
150
{
if
index
>=
150
{
return
return
}
}
}
}
}
}
}
...
@@ -54,13 +52,11 @@ func TestWheels(t *testing.T) {
...
@@ -54,13 +52,11 @@ func TestWheels(t *testing.T) {
defer
wg
.
Done
()
defer
wg
.
Done
()
var
index
int
var
index
int
for
{
for
{
select
{
<-
wheel
.
After
(
d
)
case
<-
wheel
.
After
(
d
)
:
fmt
.
Println
(
"loop:"
,
index
,
", interval:"
,
d
)
fmt
.
Println
(
"loop:"
,
index
,
", interval:"
,
d
)
index
++
index
++
if
index
>=
100
{
if
index
>=
100
{
return
return
}
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment