0

I have a redux saga setup where for some reason my channel blocks when I'm trying to take from it and I can't work out why.

I have a PubSub mechanism which subscribes to an event and when received calls this function:

const sendRoundEnd = (msg, data) => {
  console.log('putting round end')
  roundEndChannel.put({
    type: RUN_ENDED,
    data: data.payload
  })
}

I have a watcher for this channel defined like this:

function* watchRoundEndChannel() {
  while(true) {
    console.log('before take')
    const action = yield take(roundEndChannel)
    console.log('after take')
    yield put(action)
  }
}

And I have a reducer setup which is listening for the put of RUN_ENDED like this:

case RUN_ENDED:
  console.log(action)
  return {
    ...state,
    isRunning: false,
    roundResult: action.data
  }

Finally, I have a roundEndChannel const within the file (but not within the functions) and I export the following function as part of an array which is fed into yield all[]:

takeEvery(roundEndChannel, watchRoundEndChannel)

So if my understanding is right, when I get the msg from my pubsub I should first hit sendRoundEnd which puts to roundEndChannel which should in turn put the RUN_ENDED action.

What's weird however is that when I run these functions and receive the message from the pubsub, the following is logged:

putting round end
before take

I never get to the after take which suggests to me that the channel doesn't have anything in it, but I'm pretty sure that isn't the case as it should have been put to in the event handler of the pubsub immediately prior.

It feels like I'm missing something simple here, does anyone have any ideas (or ways I can examine the channel at different points to see what's in there?)

dougajmcdonald
  • 19,231
  • 12
  • 56
  • 89

1 Answers1

0

Arg, managed to fix this. The problem was I had exported the watchRoundEndChannel wrapped in a takeEvery which was snatching my pushed events up.

I exported the function like this fork(watchRoundEndChannel) and things work as I expected.

dougajmcdonald
  • 19,231
  • 12
  • 56
  • 89