Skip to content
代码片段 群组 项目
未验证 提交 306a95cd 编辑于 作者: z77ma's avatar z77ma 提交者: GitHub
浏览文件

Fix: The next event handler is not called if the previous event handler removes itself (#39716)

上级 123425e6
No related branches found
No related tags found
无相关合并请求
......@@ -674,8 +674,9 @@ export class HubConnection {
private _invokeClientMethod(invocationMessage: InvocationMessage) {
const methods = this._methods[invocationMessage.target.toLowerCase()];
if (methods) {
const methodsCopy = methods.slice();
try {
methods.forEach((m) => m.apply(this, invocationMessage.arguments));
methodsCopy.forEach((m) => m.apply(this, invocationMessage.arguments));
} catch (e) {
this._logger.log(LogLevel.Error, `A callback for the method ${invocationMessage.target.toLowerCase()} threw error '${e}'.`);
}
......
......@@ -918,6 +918,52 @@ describe("HubConnection", () => {
});
});
it("unsubscribing dynamically doesn't affect the current invocation loop", async () => {
await VerifyLogger.run(async (logger) => {
const eventToTrack = "eventName";
const connection = new TestConnection();
const hubConnection = createHubConnection(connection, logger);
try {
await hubConnection.start();
let numInvocations1 = 0;
let numInvocations2 = 0;
const callback1 = () => {
hubConnection.off(eventToTrack, callback1);
numInvocations1++;
}
const callback2 = () => numInvocations2++;
hubConnection.on(eventToTrack, callback1);
hubConnection.on(eventToTrack, callback2);
connection.receive({
arguments: [],
nonblocking: true,
target: eventToTrack,
type: MessageType.Invocation,
});
expect(numInvocations1).toBe(1);
expect(numInvocations2).toBe(1);
connection.receive({
arguments: [],
nonblocking: true,
target: eventToTrack,
type: MessageType.Invocation,
});
expect(numInvocations1).toBe(1);
expect(numInvocations2).toBe(2);
}
finally {
await hubConnection.stop();
}
});
});
it("unsubscribing from non-existing callbacks no-ops", async () => {
await VerifyLogger.run(async (logger) => {
const connection = new TestConnection();
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册