-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from zweihander/rpc-unit-tests
client: RPC engine
- Loading branch information
Showing
10 changed files
with
588 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// NotifyAcks notifies engine about received acknowledgements. | ||
func (e *Engine) NotifyAcks(ids []int64) { | ||
for _, id := range ids { | ||
e.mux.Lock() | ||
cb, ok := e.ack[id] | ||
e.mux.Unlock() | ||
|
||
if !ok { | ||
e.log.Warn("ack callback not set", zap.Int64("msg_id", id)) | ||
continue | ||
} | ||
|
||
cb() | ||
} | ||
} | ||
|
||
// waitAck blocks until acknowledgement on message id is received. | ||
func (e *Engine) waitAck(ctx context.Context, id int64) error { | ||
got := make(chan struct{}) | ||
|
||
e.mux.Lock() | ||
e.ack[id] = func() { close(got) } | ||
e.mux.Unlock() | ||
|
||
defer func() { | ||
e.mux.Lock() | ||
delete(e.ack, id) | ||
e.mux.Unlock() | ||
}() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
case <-got: | ||
return nil | ||
} | ||
} |
Oops, something went wrong.