Skip to content
Snippets Groups Projects
Commit e687051e authored by Jonah Husson's avatar Jonah Husson
Browse files

Fix listen to return an interface for stopping

parent 4decb591
No related branches found
No related tags found
2 merge requests!510Release,!296Fix listen to return an interface for stopping
...@@ -77,20 +77,20 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload, ...@@ -77,20 +77,20 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload,
// //
// Returns: // Returns:
// - StopFunc - a function used to stop the listener // - StopFunc - a function used to stop the listener
func Listen(e2eID int, tag string, cb SingleUseCallback) (StopFunc, error) { func Listen(e2eID int, tag string, cb SingleUseCallback) (Stopper, error) {
e2eCl, err := e2eTrackerSingleton.get(e2eID) e2eCl, err := e2eTrackerSingleton.get(e2eID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
listener := singleUseListener{scb: cb} suListener := singleUseListener{scb: cb}
dhpk, err := e2eCl.api.GetReceptionIdentity().GetDHKeyPrivate() dhpk, err := e2eCl.api.GetReceptionIdentity().GetDHKeyPrivate()
if err != nil { if err != nil {
return nil, err return nil, err
} }
l := single.Listen(tag, e2eCl.api.GetReceptionIdentity().ID, dhpk, l := single.Listen(tag, e2eCl.api.GetReceptionIdentity().ID, dhpk,
e2eCl.api.GetCmix(), e2eCl.api.GetStorage().GetE2EGroup(), listener) e2eCl.api.GetCmix(), e2eCl.api.GetStorage().GetE2EGroup(), suListener)
return l.Stop, nil return &stopper{l: l}, nil
} }
// JSON Types // JSON Types
...@@ -153,9 +153,10 @@ type SingleUseCallbackReport struct { ...@@ -153,9 +153,10 @@ type SingleUseCallbackReport struct {
// Function Types // // Function Types //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// StopFunc is the function to stop a listener returned to the bindings layer // Stopper is a public interface returned by Listen, allowing users to stop the registered listener.
// when one is started. type Stopper interface {
type StopFunc func() Stop()
}
// SingleUseCallback func is passed into Listen and called when messages are // SingleUseCallback func is passed into Listen and called when messages are
// received. // received.
...@@ -209,6 +210,18 @@ func (sl singleUseListener) Callback( ...@@ -209,6 +210,18 @@ func (sl singleUseListener) Callback(
sl.scb.Callback(json.Marshal(scr)) 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 */ /* Response Struct */
// singleUseResponse is the private struct backing SingleUseResponse, which // singleUseResponse is the private struct backing SingleUseResponse, which
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment