Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-eventbus
Commits
0976d4b3
Commit
0976d4b3
authored
Jun 25, 2019
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable buffering by default
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
61257f90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
basic.go
basic.go
+2
-1
basic_test.go
basic_test.go
+11
-0
opts.go
opts.go
+4
-0
No files found.
basic.go
View file @
0976d4b3
...
...
@@ -129,7 +129,7 @@ var _ event.Subscription = (*sub)(nil)
// publishers to get blocked. CancelFunc is guaranteed to return after last send
// to the channel
func
(
b
*
basicBus
)
Subscribe
(
evtTypes
interface
{},
opts
...
event
.
SubscriptionOpt
)
(
_
event
.
Subscription
,
err
error
)
{
var
s
ettings
subSettings
settings
:=
subS
ettings
(
subSettings
Default
)
for
_
,
opt
:=
range
opts
{
if
err
:=
opt
(
&
settings
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -184,6 +184,7 @@ func (b *basicBus) Subscribe(evtTypes interface{}, opts ...event.SubscriptionOpt
// emit(EventT{})
func
(
b
*
basicBus
)
Emitter
(
evtType
interface
{},
opts
...
event
.
EmitterOpt
)
(
e
event
.
Emitter
,
err
error
)
{
var
settings
emitterSettings
for
_
,
opt
:=
range
opts
{
if
err
:=
opt
(
&
settings
);
err
!=
nil
{
return
nil
,
err
...
...
basic_test.go
View file @
0976d4b3
...
...
@@ -25,6 +25,17 @@ func (EventA) String() string {
return
"Oh, Hello"
}
func
TestDefaultSubIsBuffered
(
t
*
testing
.
T
)
{
bus
:=
NewBus
()
s
,
err
:=
bus
.
Subscribe
(
new
(
EventA
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
cap
(
s
.
(
*
sub
)
.
ch
)
==
0
{
t
.
Fatalf
(
"without any options subscribe should be buffered. was %d"
,
cap
(
s
.
(
*
sub
)
.
ch
))
}
}
func
TestEmit
(
t
*
testing
.
T
)
{
bus
:=
NewBus
()
sub
,
err
:=
bus
.
Subscribe
(
new
(
EventA
))
...
...
opts.go
View file @
0976d4b3
...
...
@@ -4,6 +4,10 @@ type subSettings struct {
buffer
int
}
var
subSettingsDefault
=
subSettings
{
buffer
:
16
,
}
func
BufSize
(
n
int
)
func
(
interface
{})
error
{
return
func
(
s
interface
{})
error
{
s
.
(
*
subSettings
)
.
buffer
=
n
...
...
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