Skip to content

Commit b9699cd

Browse files
committed
fix: 修复waitFor无法等待一个retain=true消息的问题
1 parent fa70b58 commit b9699cd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/native/src/__tests__/waitFor.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ describe("waitfor", () => {
203203

204204
});
205205

206+
test('等待retain事件时马上返回', async () => {
207+
const emitter = new FastEvent();
208+
209+
emitter.emit("x", 1, true)
210+
211+
// Arrange
212+
const results = await emitter.waitFor('x', 500);
213+
214+
expect(results).toEqual({
215+
type: 'x',
216+
payload: 1,
217+
meta: undefined
218+
});
219+
220+
221+
});
222+
206223

207224

208225
})

packages/native/src/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ export class FastEvent<
868868
let subscriber: FastEventSubscriber
869869
const listener = (message: TypedFastEventMessage<AllEvents, Meta>) => {
870870
clearTimeout(tid)
871-
subscriber.off()
871+
subscriber && subscriber.off()
872872
resolve(message)
873873
}
874874
if (timeout && timeout > 0) {

0 commit comments

Comments
 (0)