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
dms3
go-bitswap
Commits
097bc1b4
Commit
097bc1b4
authored
Nov 21, 2014
by
Brian Tiger Chow
Committed by
Jeromy
Dec 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bitswap/notifications) subscribe to many
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
a6371b4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
4 deletions
+47
-4
notifications/notifications.go
notifications/notifications.go
+47
-4
No files found.
notifications/notifications.go
View file @
097bc1b4
...
@@ -29,10 +29,7 @@ func (ps *impl) Publish(block *blocks.Block) {
...
@@ -29,10 +29,7 @@ func (ps *impl) Publish(block *blocks.Block) {
ps
.
wrapped
.
Pub
(
block
,
topic
)
ps
.
wrapped
.
Pub
(
block
,
topic
)
}
}
// Subscribe returns a channel of blocks for the given |keys|. |blockChannel|
func
(
ps
*
impl
)
SubscribeDeprec
(
ctx
context
.
Context
,
keys
...
u
.
Key
)
<-
chan
*
blocks
.
Block
{
// is closed if the |ctx| times out or is cancelled, or after sending len(keys)
// blocks.
func
(
ps
*
impl
)
Subscribe
(
ctx
context
.
Context
,
keys
...
u
.
Key
)
<-
chan
*
blocks
.
Block
{
topics
:=
make
([]
string
,
0
)
topics
:=
make
([]
string
,
0
)
for
_
,
key
:=
range
keys
{
for
_
,
key
:=
range
keys
{
topics
=
append
(
topics
,
string
(
key
))
topics
=
append
(
topics
,
string
(
key
))
...
@@ -57,3 +54,49 @@ func (ps *impl) Subscribe(ctx context.Context, keys ...u.Key) <-chan *blocks.Blo
...
@@ -57,3 +54,49 @@ func (ps *impl) Subscribe(ctx context.Context, keys ...u.Key) <-chan *blocks.Blo
func
(
ps
*
impl
)
Shutdown
()
{
func
(
ps
*
impl
)
Shutdown
()
{
ps
.
wrapped
.
Shutdown
()
ps
.
wrapped
.
Shutdown
()
}
}
// Subscribe returns a channel of blocks for the given |keys|. |blockChannel|
// is closed if the |ctx| times out or is cancelled, or after sending len(keys)
// blocks.
func
(
ps
*
impl
)
Subscribe
(
ctx
context
.
Context
,
keys
...
u
.
Key
)
<-
chan
*
blocks
.
Block
{
topics
:=
toStrings
(
keys
)
blocksCh
:=
make
(
chan
*
blocks
.
Block
,
len
(
keys
))
valuesCh
:=
make
(
chan
interface
{},
len
(
keys
))
ps
.
wrapped
.
AddSub
(
valuesCh
,
topics
...
)
go
func
()
{
defer
func
()
{
ps
.
wrapped
.
Unsub
(
valuesCh
,
topics
...
)
close
(
blocksCh
)
}()
for
_
,
_
=
range
keys
{
select
{
case
<-
ctx
.
Done
()
:
return
case
val
,
ok
:=
<-
valuesCh
:
if
!
ok
{
return
}
block
,
ok
:=
val
.
(
*
blocks
.
Block
)
if
!
ok
{
return
}
select
{
case
<-
ctx
.
Done
()
:
return
case
blocksCh
<-
block
:
// continue
}
}
}
}()
return
blocksCh
}
func
toStrings
(
keys
[]
u
.
Key
)
[]
string
{
strs
:=
make
([]
string
,
0
)
for
_
,
key
:=
range
keys
{
strs
=
append
(
strs
,
string
(
key
))
}
return
strs
}
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