Skip to content

Commit

Permalink
Server#addService - lift the limitation of adding a new service to st…
Browse files Browse the repository at this point in the history
…arted server
  • Loading branch information
hugebdu committed Oct 29, 2020
1 parent afe4c3e commit e49524a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions packages/grpc-js/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ export class Server {
service: ServiceDefinition,
implementation: UntypedServiceImplementation
): void {
if (this.started === true) {
throw new Error("Can't add a service to a started server.");
}

if (
service === null ||
typeof service !== 'object' ||
Expand Down Expand Up @@ -637,7 +633,7 @@ async function handleUnary<RequestType, ResponseType>(
if (request === undefined || call.cancelled) {
return;
}

const emitter = new ServerUnaryCallImpl<RequestType, ResponseType>(
call,
metadata,
Expand Down
6 changes: 3 additions & 3 deletions packages/grpc-js/test/test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('Server', () => {
});
});

it('fails if the server has been started', done => {
it('succeeds after server has been started', done => {
const server = new Server();

server.bindAsync(
Expand All @@ -211,9 +211,9 @@ describe('Server', () => {
(err, port) => {
assert.ifError(err);
server.start();
assert.throws(() => {
assert.doesNotThrow(() => {
server.addService(mathServiceAttrs, dummyImpls);
}, /Can't add a service to a started server\./);
});
server.tryShutdown(done);
}
);
Expand Down

0 comments on commit e49524a

Please sign in to comment.