Skip to content

Commit

Permalink
feat: allow to close client (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored May 26, 2024
1 parent 50a0358 commit ef1c372
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 10 additions & 5 deletions demo/helloworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ const client = new Client();
assert(client);

async function main() {
const hello = await client.hello.sayHello({
serviceName: 'helloworld',
name: 'js-sdk',
});
console.log('%s', hello);
try {
const hello = await client.hello.sayHello({
serviceName: 'helloworld',
name: 'js-sdk',
});
console.log('%s', hello);
} catch (err) {
console.error('sayHello error: %s', err);
}
client.close();
}

main();
4 changes: 4 additions & 0 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,8 @@ export class Client {
}
return this._cryption;
}

close() {
this._runtime.close();
}
}
10 changes: 9 additions & 1 deletion test/unit/client/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Client } from '../../../src';
import { CreateMetadataHook } from '../../../src/client/API';
import { CustomClient } from './fixtures/CustomClient';

describe('client/Client.test.ts', () => {
describe('test/unit/client/Client.test.ts', () => {
let client: Client;
beforeAll(async () => {
client = new Client();
Expand All @@ -32,6 +32,10 @@ describe('client/Client.test.ts', () => {
assert(client.state);
});

afterAll(() => {
client.close();
});

describe('custom Client', () => {
let customClient: CustomClient;
beforeAll(() => {
Expand All @@ -54,5 +58,9 @@ describe('client/Client.test.ts', () => {
const hello2 = await customClient.hello.sayHello({ name: 'js-sdk' });
assert.equal(hello2, 'greeting, js-sdk');
});

afterAll(() => {
customClient.close();
});
});
});

0 comments on commit ef1c372

Please sign in to comment.