websocket同步问题(解决同时最多发起 5 个 socket 请求限制)?
直接上代码:
var getState = function (url) {
return new Promise(resolve => {
var ws = wx.connectSocket({
url: url,
data: {},
method: 'GET',
success(res) {},
fail() {}
});
ws.onOpen((res) => {
ws.send({data: "发送请求"});
});
ws.onMessage((res) => {
resolve(res);
ws && ws.close();
});
});
}
// 调用
arrData.forEach(async (item, index) => {
await getState(url).then((res) => {
console.log('处理中...' + index);
});
console.log('成功处理!' + index);
});
// 错误提示:
处理中...0
成功处理!0
处理中...1
成功处理!1
同时最多发起 5 个 socket 请求,更多请参考文档
Uncaught (in promise) thirdScriptError
{"errMsg":"closeSocket:fail task not found"}
Object
可以同步,但好像关不了socket ?