'[Redux-saga][EventChannel] When two events are triggered at the same time, I cannot intercept these events in the channel

When the typing indicator and the added message events are triggered at the same time, the channel does not catch these events.

const eventListener = (channel) => eventChannel((emit) => {
  const handler = (data) => {
    emit(data);
  };

  if (channel) {
    channel.on(ChannelEvents.MESSAGE_ADDED, (payload) => handler({
      type: ChannelEvents.MESSAGE_ADDED, payload,
    }));
    channel.on(ChannelEvents.TYPING_STARTED, (payload) => handler({
      type: ChannelEvents.TYPING_STARTED, payload,
    }));
    channel.on(ChannelEvents.TYPING_ENDED, (payload) => handler({
      type: ChannelEvents.TYPING_ENDED, payload,
    }));
    channel.on(ChannelEvents.DISCONNECT, () => {
      emit(END);
    });
  }

  return () => { };
});

 const channel = yield call(eventListener, systemChannel);

  while (true) {
    const { payload, type } = yield take(channel);
...

I tried to use take Every, but takeEvery doesn't have a queue. How to fix this without creating a own queue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source