mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-22 23:00:50 +02:00
make context work
This commit is contained in:
parent
23ddac33dd
commit
39f7a99894
@ -76,7 +76,6 @@ func ConnectBunker(
|
|||||||
pool,
|
pool,
|
||||||
onAuth,
|
onAuth,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err = bunker.RPC(ctx, "connect", []string{targetPublicKey, secret})
|
_, err = bunker.RPC(ctx, "connect", []string{targetPublicKey, secret})
|
||||||
return bunker, err
|
return bunker, err
|
||||||
}
|
}
|
||||||
@ -237,6 +236,10 @@ func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []str
|
|||||||
|
|
||||||
respWaiter := make(chan Response)
|
respWaiter := make(chan Response)
|
||||||
bunker.listeners.Store(id, respWaiter)
|
bunker.listeners.Store(id, respWaiter)
|
||||||
|
defer func() {
|
||||||
|
bunker.listeners.Delete(id)
|
||||||
|
close(respWaiter)
|
||||||
|
}()
|
||||||
hasWorked := make(chan struct{})
|
hasWorked := make(chan struct{})
|
||||||
|
|
||||||
for _, url := range bunker.relays {
|
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")
|
return "", fmt.Errorf("couldn't connect to any relay")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-respWaiter
|
select {
|
||||||
if resp.Error != "" {
|
case <-ctx.Done():
|
||||||
return "", fmt.Errorf("response error: %s", resp.Error)
|
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