Skip to content

Commit ef1c372

Browse files
authored
feat: allow to close client (#42)
1 parent 50a0358 commit ef1c372

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

demo/helloworld.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ const client = new Client();
1919
assert(client);
2020

2121
async function main() {
22-
const hello = await client.hello.sayHello({
23-
serviceName: 'helloworld',
24-
name: 'js-sdk',
25-
});
26-
console.log('%s', hello);
22+
try {
23+
const hello = await client.hello.sayHello({
24+
serviceName: 'helloworld',
25+
name: 'js-sdk',
26+
});
27+
console.log('%s', hello);
28+
} catch (err) {
29+
console.error('sayHello error: %s', err);
30+
}
31+
client.close();
2732
}
2833

2934
main();

src/client/Client.ts

+4
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,8 @@ export class Client {
193193
}
194194
return this._cryption;
195195
}
196+
197+
close() {
198+
this._runtime.close();
199+
}
196200
}

test/unit/client/Client.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Client } from '../../../src';
1717
import { CreateMetadataHook } from '../../../src/client/API';
1818
import { CustomClient } from './fixtures/CustomClient';
1919

20-
describe('client/Client.test.ts', () => {
20+
describe('test/unit/client/Client.test.ts', () => {
2121
let client: Client;
2222
beforeAll(async () => {
2323
client = new Client();
@@ -32,6 +32,10 @@ describe('client/Client.test.ts', () => {
3232
assert(client.state);
3333
});
3434

35+
afterAll(() => {
36+
client.close();
37+
});
38+
3539
describe('custom Client', () => {
3640
let customClient: CustomClient;
3741
beforeAll(() => {
@@ -54,5 +58,9 @@ describe('client/Client.test.ts', () => {
5458
const hello2 = await customClient.hello.sayHello({ name: 'js-sdk' });
5559
assert.equal(hello2, 'greeting, js-sdk');
5660
});
61+
62+
afterAll(() => {
63+
customClient.close();
64+
});
5765
});
5866
});

0 commit comments

Comments
 (0)