Create Invoker object

This commit is contained in:
David Gardiner 2023-01-03 13:36:05 -08:00
parent faabdc247b
commit 731ba682f2
17 changed files with 152 additions and 105 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/cli/cli/v2/internal/codespaces/api"
"github.com/cli/cli/v2/internal/codespaces/rpc"
"github.com/cli/cli/v2/pkg/liveshare"
)
@ -79,3 +80,16 @@ func ConnectToLiveshare(ctx context.Context, progress progressIndicator, session
Logger: sessionLogger,
})
}
// Helper function to connect to the internal RPC server and return an RPC invoker for it
func CreateRPCInvoker(ctx context.Context, session *liveshare.Session, token string) (*rpc.Invoker, error) {
ctx, cancel := context.WithTimeout(ctx, rpc.ConnectionTimeout)
defer cancel()
invoker, err := rpc.Connect(ctx, session, token)
if err != nil {
return nil, fmt.Errorf("error connecting to internal server: %w", err)
}
return invoker, nil
}