Websocket 重演传奇,同时实现真正的连续调用

Websocket 重演传奇,同时实现真正的连续调用,websocket,redux-saga,Websocket,Redux Saga,我尝试用redux传奇实现WebSocket 我发现这个实现: function* flow() { while (true) { let { payload } = yield take(`${login}`); const socket = yield call(connect); socket.emit('login', { username: payload.username }); const task = yield fork(handleIO,

我尝试用redux传奇实现WebSocket

我发现这个实现:

function* flow() {
  while (true) {
    let { payload } = yield take(`${login}`);
    const socket = yield call(connect);
    socket.emit('login', { username: payload.username });

    const task = yield fork(handleIO, socket);

    let action = yield take(`${logout}`);
    yield cancel(task);
    socket.emit('logout');
  }
}

export default function* rootSaga() {
  yield fork(flow);
}
我已经从这里复制了实现:

问题是while true完全淹没了WebSocket连接。它连接,连接,洪水和崩溃的应用程序

所以我在这里寻找一些提示;很明显,关于传奇故事或生成器函数,或者两者,我都不了解

为什么上面的聊天实现可以在不淹没WebSocket connect的情况下工作,为什么我的实现会失败并不断尝试连接


非常感谢。

下面是您的代码执行过程:

run this forever
  waits for a "login" action (pauses the generator and the while loop)
  calling connect (does not pause the generator)
  emitting "login" via the socket (does not stop the generator)
  forking handleIO (does not pause the generator)
  waits for a "logout" action (pauses the generator and the while loop)
  canceling what handleIO is doing (does not pause the generator)
  emitting "logout" via the socket (does not pause the generator)
这里有几个提示:

您是否需要等待连接是否真正连接到套接字服务器。或者它会回报一个承诺? 你有什么东西可以发送注销操作吗。我这样问是因为这和登录是唯一一件让while循环一次又一次运行的事情。 你确定你只运行了一次rootSaga吗? 附言。 `${login}`可以简单地写为'login'