1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Add StringID call option (#44)

Fixes #43
This commit is contained in:
Sam Herrmann 2021-04-26 03:12:26 -04:00 committed by GitHub
parent 366fbb5207
commit 08fd77d0de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 47 deletions

View file

@ -366,9 +366,14 @@ func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err
// responses.
if m.request != nil && wait {
cc = &call{request: m.request, seq: c.seq, done: make(chan error, 1)}
if !m.request.ID.IsString && m.request.ID.Num == 0 {
// unset, use next seq as call ID
m.request.ID.Num = c.seq
isIDUnset := len(m.request.ID.Str) == 0 && m.request.ID.Num == 0
if isIDUnset {
if m.request.ID.IsString {
m.request.ID.Str = strconv.FormatUint(c.seq, 10)
} else {
m.request.ID.Num = c.seq
}
}
id = m.request.ID
c.pending[id] = cc