React native 当某个动作出现时,如何关闭eventChannel
我有一个用于收听WebSocket的eventChannel,这很好用 我还想听到一个动作用户退出并关闭频道 在套接字错误或套接字关闭的情况下,我通过发出END从通道内部关闭通道,但是如何基于外部操作来实现这一点 这是通道环路:React native 当某个动作出现时,如何关闭eventChannel,react-native,redux-saga,React Native,Redux Saga,我有一个用于收听WebSocket的eventChannel,这很好用 我还想听到一个动作用户退出并关闭频道 在套接字错误或套接字关闭的情况下,我通过发出END从通道内部关闭通道,但是如何基于外部操作来实现这一点 这是通道环路: export function* websocketWatcher() { const tokenResponse = yield take(RECEIVE_USER_TOKEN); const accessToken = tokenResponse.paylo
export function* websocketWatcher() {
const tokenResponse = yield take(RECEIVE_USER_TOKEN);
const accessToken = tokenResponse.payload.data.access_token;
const channel = yield call(createWebsocketChannel, accessToken);
try {
while (true) {
const action = yield take(channel);
yield put(action);
}
} finally {
console.log('Websocket channel terminated');
}
}
我自己回答 我刚在文档中找到channel.close。不知道我怎么会错过。我通过通道传入套接字数据和注销操作之间的竞争解决了这个问题
export function* websocketWatcher() {
const tokenResponse = yield take(RECEIVE_USER_TOKEN);
const accessToken = tokenResponse.payload.data.access_token;
const channel = yield call(createWebsocketChannel, accessToken);
try {
while (true) {
const { logoutAction, socketAction } = yield race({
logoutAction: take(USER_LOGGED_OUT),
socketAction: take(channel)
});
if (logoutAction) {
channel.close();
} else {
yield put(socketAction);
}
}
} finally {
console.log('Websocket channel terminated');
}
}
我自己回答 我刚在文档中找到channel.close。不知道我怎么会错过。我通过通道传入套接字数据和注销操作之间的竞争解决了这个问题
export function* websocketWatcher() {
const tokenResponse = yield take(RECEIVE_USER_TOKEN);
const accessToken = tokenResponse.payload.data.access_token;
const channel = yield call(createWebsocketChannel, accessToken);
try {
while (true) {
const { logoutAction, socketAction } = yield race({
logoutAction: take(USER_LOGGED_OUT),
socketAction: take(channel)
});
if (logoutAction) {
channel.close();
} else {
yield put(socketAction);
}
}
} finally {
console.log('Websocket channel terminated');
}
}
你最后做了什么?当它被终止时?最终做什么?何时终止?