Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/vs/base/parts/ipc/common/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ export class ChannelClient implements IChannelClient, IDisposable {

const emitter = new Emitter<any>({
onWillAddFirstListener: () => {
const handler: IHandler = (res: IRawResponse) => emitter.fire((res as IRawEventFireResponse).data);
this.handlers.set(id, handler);
const doRequest = () => {
this.activeRequests.add(emitter);
this.sendRequest(request);
Expand All @@ -706,9 +708,6 @@ export class ChannelClient implements IChannelClient, IDisposable {
}
});

const handler: IHandler = (res: IRawResponse) => emitter.fire((res as IRawEventFireResponse).data);
this.handlers.set(id, handler);

return emitter.event;
}

Expand Down
42 changes: 42 additions & 0 deletions src/vs/base/parts/ipc/test/common/ipc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,27 @@ suite('Base IPC', function () {
assert.deepStrictEqual(messages, ['hello', 'world']);
});

test('listen to events (resubscribe)', async function () {
const onPong = ipcService.onPong;
const messages: string[] = [];

const disposable1 = onPong(msg => messages.push(msg));
await timeout(0);
assert.deepStrictEqual(messages, []);
service.ping('hello');
await timeout(0);
assert.deepStrictEqual(messages, ['hello']);
disposable1.dispose();

const disposable2 = onPong(msg => (messages as string[]).push(msg));
await timeout(0);
assert.deepStrictEqual(messages, ['hello']);
service.ping('world');
await timeout(0);
assert.deepStrictEqual(messages, ['hello', 'world']);
disposable2.dispose();
});

test('buffers in arrays', async function () {
const r = await ipcService.buffersLength([VSBuffer.alloc(2), VSBuffer.alloc(3)]);
return assert.strictEqual(r, 5);
Expand Down Expand Up @@ -443,6 +464,27 @@ suite('Base IPC', function () {
assert.deepStrictEqual(messages, ['hello', 'world']);
});

test('listen to events (resubscribe)', async function () {
const onPong = ipcService.onPong;
const messages: string[] = [];

const disposable1 = onPong(msg => messages.push(msg));
await timeout(0);
assert.deepStrictEqual(messages, []);
service.ping('hello');
await timeout(0);
assert.deepStrictEqual(messages, ['hello']);
disposable1.dispose();

const disposable2 = onPong(msg => (messages as string[]).push(msg));
await timeout(0);
assert.deepStrictEqual(messages, ['hello']);
service.ping('world');
await timeout(0);
assert.deepStrictEqual(messages, ['hello', 'world']);
disposable2.dispose();
});

test('marshalling uri', async function () {
const uri = URI.file('foobar');
const r = await ipcService.marshall(uri);
Expand Down
Loading