Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
e687051e
Commit
e687051e
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Fix listen to return an interface for stopping
parent
4decb591
No related branches found
No related tags found
2 merge requests
!510
Release
,
!296
Fix listen to return an interface for stopping
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/single.go
+20
-7
20 additions, 7 deletions
bindings/single.go
with
20 additions
and
7 deletions
bindings/single.go
+
20
−
7
View file @
e687051e
...
...
@@ -77,20 +77,20 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload,
//
// Returns:
// - StopFunc - a function used to stop the listener
func
Listen
(
e2eID
int
,
tag
string
,
cb
SingleUseCallback
)
(
Stop
Func
,
error
)
{
func
Listen
(
e2eID
int
,
tag
string
,
cb
SingleUseCallback
)
(
Stop
per
,
error
)
{
e2eCl
,
err
:=
e2eTrackerSingleton
.
get
(
e2eID
)
if
err
!=
nil
{
return
nil
,
err
}
l
istener
:=
singleUseListener
{
scb
:
cb
}
suL
istener
:=
singleUseListener
{
scb
:
cb
}
dhpk
,
err
:=
e2eCl
.
api
.
GetReceptionIdentity
()
.
GetDHKeyPrivate
()
if
err
!=
nil
{
return
nil
,
err
}
l
:=
single
.
Listen
(
tag
,
e2eCl
.
api
.
GetReceptionIdentity
()
.
ID
,
dhpk
,
e2eCl
.
api
.
GetCmix
(),
e2eCl
.
api
.
GetStorage
()
.
GetE2EGroup
(),
l
istener
)
return
l
.
Stop
,
nil
e2eCl
.
api
.
GetCmix
(),
e2eCl
.
api
.
GetStorage
()
.
GetE2EGroup
(),
suL
istener
)
return
&
stopper
{
l
:
l
}
,
nil
}
// JSON Types
...
...
@@ -153,9 +153,10 @@ type SingleUseCallbackReport struct {
// Function Types //
////////////////////////////////////////////////////////////////////////////////
// StopFunc is the function to stop a listener returned to the bindings layer
// when one is started.
type
StopFunc
func
()
// Stopper is a public interface returned by Listen, allowing users to stop the registered listener.
type
Stopper
interface
{
Stop
()
}
// SingleUseCallback func is passed into Listen and called when messages are
// received.
...
...
@@ -209,6 +210,18 @@ func (sl singleUseListener) Callback(
sl
.
scb
.
Callback
(
json
.
Marshal
(
scr
))
}
/* Listener stopper */
// stopper is the internal struct backing the Stopper interface, allowing us
// to pass the listener Stop method to the bindings layer.
type
stopper
struct
{
l
single
.
Listener
}
func
(
s
*
stopper
)
Stop
()
{
s
.
l
.
Stop
()
}
/* Response Struct */
// singleUseResponse is the private struct backing SingleUseResponse, which
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment