internal/jsonrpc2_v2: rename Serve to NewServer and eliminate its error return

Serve had a misleading name and signature: it did not actually block
on serving the connection, and never returned a non-nil error.

Updates golang/go#56281.

Change-Id: Ia6df0ba20066811b0551df3b3267dff2fffd7881
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443678
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
Bryan C. Mills 2022-10-18 12:06:21 -04:00 • committed by Gopher Robot
commit a482202a17

View file

@ -63,21 +63,21 @@ func Dial(ctx context.Context, dialer Dialer, binder Binder) (*Connection, error
return newConnection(ctx, rwc, binder, nil), nil
}
// Serve starts a new server listening for incoming connections and returns
// NewServer starts a new server listening for incoming connections and returns
// it.
// This returns a fully running and connected server, it does not block on
// the listener.
// You can call Wait to block on the server, or Shutdown to get the sever to
// terminate gracefully.
// To notice incoming connections, use an intercepting Binder.
func Serve(ctx context.Context, listener Listener, binder Binder) (*Server, error) {
func NewServer(ctx context.Context, listener Listener, binder Binder) *Server {
server := &Server{
listener: listener,
binder: binder,
async: newAsync(),
}
go server.run(ctx)
return server, nil
return server
}
// Wait returns only when the server has shut down.