Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9f01136d
Commit
9f01136d
authored
Aug 10, 2016
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Federation - common libs - small changes in delaying deliverer
parent
d611e611
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
5 deletions
+29
-5
delaying_deliverer.go
...tion/pkg/federation-controller/util/delaying_deliverer.go
+27
-4
delaying_deliverer_test.go
...pkg/federation-controller/util/delaying_deliverer_test.go
+2
-1
No files found.
federation/pkg/federation-controller/util/delaying_deliverer.go
View file @
9f01136d
...
...
@@ -81,8 +81,12 @@ type DelayingDeliverer struct {
stopChannel
chan
struct
{}
}
func
NewDelayingDeliverer
(
targetChannel
chan
*
DelayingDelivererItem
)
*
DelayingDeliverer
{
d
:=
&
DelayingDeliverer
{
func
NewDelayingDeliverer
()
*
DelayingDeliverer
{
return
NewDelayingDelivererWithChannel
(
make
(
chan
*
DelayingDelivererItem
,
100
))
}
func
NewDelayingDelivererWithChannel
(
targetChannel
chan
*
DelayingDelivererItem
)
*
DelayingDeliverer
{
return
&
DelayingDeliverer
{
targetChannel
:
targetChannel
,
heap
:
&
delivererHeap
{
keyPosition
:
make
(
map
[
string
]
int
),
...
...
@@ -91,8 +95,6 @@ func NewDelayingDeliverer(targetChannel chan *DelayingDelivererItem) *DelayingDe
updateChannel
:
make
(
chan
*
DelayingDelivererItem
,
delayingDelivererUpdateChanCapacity
),
stopChannel
:
make
(
chan
struct
{}),
}
go
d
.
run
()
return
d
}
// Deliver all items due before or equal to timestamp.
...
...
@@ -136,6 +138,12 @@ func (d *DelayingDeliverer) run() {
}
}
// Starts the DelayingDeliverer.
func
(
d
*
DelayingDeliverer
)
Start
()
{
go
d
.
run
()
}
// Stops the DelayingDeliverer. Undelivered items are discarded.
func
(
d
*
DelayingDeliverer
)
Stop
()
{
close
(
d
.
stopChannel
)
}
...
...
@@ -158,3 +166,18 @@ func (d *DelayingDeliverer) DeliverAfter(key string, value interface{}, delay ti
func
(
d
*
DelayingDeliverer
)
GetTargetChannel
()
chan
*
DelayingDelivererItem
{
return
d
.
targetChannel
}
// Starts Delaying deliverer with a handler listening on the target channel.
func
(
d
*
DelayingDeliverer
)
StartWithHandler
(
handler
func
(
*
DelayingDelivererItem
))
{
go
func
()
{
for
{
select
{
case
item
:=
<-
d
.
targetChannel
:
handler
(
item
)
case
<-
d
.
stopChannel
:
return
}
}
}()
d
.
Start
()
}
federation/pkg/federation-controller/util/delaying_deliverer_test.go
View file @
9f01136d
...
...
@@ -26,7 +26,8 @@ import (
func
TestDelayingDeliverer
(
t
*
testing
.
T
)
{
targetChannel
:=
make
(
chan
*
DelayingDelivererItem
)
now
:=
time
.
Now
()
d
:=
NewDelayingDeliverer
(
targetChannel
)
d
:=
NewDelayingDelivererWithChannel
(
targetChannel
)
d
.
Start
()
defer
d
.
Stop
()
startupDelay
:=
time
.
Second
d
.
DeliverAt
(
"a"
,
"aaa"
,
now
.
Add
(
startupDelay
+
2
*
time
.
Millisecond
))
...
...
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