good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 0ccdaeac authored by a's avatar a
Browse files

shitty

parent 77e8366b
No related branches found
No related tags found
No related merge requests found
Pipeline #24788 failed
package client
import (
"context"
"sync"
"gfx.cafe/open/jrpc"
"gfx.cafe/open/jrpc/pkg/codec"
)
type Reconnecting struct {
dialer func(ctx context.Context) (jrpc.Conn, error)
base codec.Conn
middleware []codec.Middleware
mu sync.Mutex
}
func NewReconnecting(dialer func(ctx context.Context) (jrpc.Conn, error)) *Reconnecting {
r := &Reconnecting{
dialer: dialer,
}
return r
}
func (r *Reconnecting) getClient(ctx context.Context) (jrpc.Conn, error) {
return r.base, nil
}
func (r *Reconnecting) Do(ctx context.Context, result any, method string, params any) error {
errChan := make(chan error)
go func() {
conn, err := r.getClient(ctx)
if err != nil {
errChan <- err
return
}
errChan <- conn.Do(ctx, result, method, params)
}()
return <-errChan
}
func (r *Reconnecting) BatchCall(ctx context.Context, b ...*codec.BatchElem) error {
errChan := make(chan error)
go func() {
conn, err := r.getClient(ctx)
if err != nil {
errChan <- err
return
}
errChan <- conn.BatchCall(ctx, b...)
}()
return <-errChan
}
func (r *Reconnecting) Mount(m codec.Middleware) {
r.middleware = append(r.middleware, m)
}
// why would you want to do this....
func (r *Reconnecting) Close() error {
return nil
}
// never....
func (r *Reconnecting) Closed() <-chan struct{} {
return make(<-chan struct{})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment