mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
make context work
This commit is contained in:
parent
23ddac33dd
commit
39f7a99894
@ -76,7 +76,6 @@ func ConnectBunker(
|
||||
pool,
|
||||
onAuth,
|
||||
)
|
||||
|
||||
_, err = bunker.RPC(ctx, "connect", []string{targetPublicKey, secret})
|
||||
return bunker, err
|
||||
}
|
||||
@ -237,6 +236,10 @@ func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []str
|
||||
|
||||
respWaiter := make(chan Response)
|
||||
bunker.listeners.Store(id, respWaiter)
|
||||
defer func() {
|
||||
bunker.listeners.Delete(id)
|
||||
close(respWaiter)
|
||||
}()
|
||||
hasWorked := make(chan struct{})
|
||||
|
||||
for _, url := range bunker.relays {
|
||||
@ -259,10 +262,13 @@ func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []str
|
||||
return "", fmt.Errorf("couldn't connect to any relay")
|
||||
}
|
||||
|
||||
resp := <-respWaiter
|
||||
if resp.Error != "" {
|
||||
return "", fmt.Errorf("response error: %s", resp.Error)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", fmt.Errorf("context canceled")
|
||||
case resp := <-respWaiter:
|
||||
if resp.Error != "" {
|
||||
return "", fmt.Errorf("response error: %s", resp.Error)
|
||||
}
|
||||
return resp.Result, nil
|
||||
}
|
||||
|
||||
return resp.Result, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user